Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams from utils import progress_bar_downloader import os #Hosting files on my dropbox since downloading from google code is painful #Original project hosting is here: https://code.google.com/p/hmm-speech-recognition/downloads/list #Audio is included in the zip file link = 'https://dl.dropboxusercontent.com/u/15378192/audio.tar.gz' dlname = 'audio.tar.gz' if not os.path.exists('./%s' % dlname): progress_bar_downloader(link, dlname) os.system('tar xzf %s' % dlname) else: print('%s already downloaded!' % dlname)

I want use matplotlib but it gives syntax error, I tried sudo apt-get install python-matplotlib

if you are not using Jupyter IPython notebook, just comment out (or delete) the line, everything will work fine and a separate plot window will be opened if you are running your python script from the console.

However, if you are using Jupyter IPython notebook, the very first python code cell in your notebook should have the line "%matplotlib inline" for you to be able to view any plot.

"%matplotlib inline" is a magic command that works best with Jupyter IPython notebook. This command makes the image automatically shows inline inside the browser when using Jupyter notebook without having to call the show(). IPython is the core that supports these magic commands, but in this case, using IPython from console alone is not enough since this particular call tries to display graphics inline. Not sure if it works with any other combo, but to start, use Jupyter notebook.

You can only use this code inside the cell. Press Shift+Enter to execute it.

In []: %matplotlib inline

Since this is not a valid python code, if we include it inside a python script it will return with a syntax error (even when the script is executed from Jupyter notebook using import or other mechanism).

As any other shortcuts, if don't want to use jupyter notebook, you can remove "%matplotlib inline" from your python script and add show() at the end to display your plots.

thanks for this solution but there is strange thing happened to me with a code that i ran it with jupyter ubuntu14.04 without this line and worked well and when i installed ubuntu 18.04 and ran code with jupyter i got the error that fixed by this line , why this problem happened? – user1 Aug 25, 2018 at 6:46

I had the same syntax error when using %matplotlib inline in Spyder.
After I replace it with the following lines of code, the Series, new_obj, that I wanted to plot successfully displayed on the console:

    import matplotlib.pyplot as plt
    new_obj.resample('M').sum().plot(kind="bar")
    plt.show()

%matplotlib inline only works well in the Ipython console or else it works very significantly and frequently in the Jupyter Notebook. So, in my suggestion if you wants to work with the Matplotlib then go for the Jupyter Notebook