Python SyntaxError: Invalid syntax% matplotlib inline

I got this error in my python script:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

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 to use matplotlib, but it gives a syntax error, I tried sudo apt-get install python-matplotlib

+4
source share
4 answers

if you are not using Jupyter IPython for the laptop, just comment out (or delete) the line, everything will work fine, and a separate graph window will open if you run your python script from the console.

If you are not using a Jupyter IPython laptop, the very first python code cell in your laptop should have the string "% matplotlib inline" so you can view any plot.

+6

"% matplotlib inline" python, script.

, Jupyter? , , .

+3

% matplotlib inline - , Jupyter IPython. inline Jupyter show(). IPython - , , IPython , . , , Jupyter.

. Shift + Enter, .

In []: %matplotlib inline

Python, Python, ( Jupyter ).

, jupyter, "% matplotlib inline" python show() , .

+1

%matplotlib Spyder.
, , Series, new_obj, , :

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

Source: https://habr.com/ru/post/1654334/


All Articles