python SyntaxError: invalid syntax %matplotlib inline
python SyntaxError: invalid syntax %matplotlib inline
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 isnt valid python code, so you cant put it in a script.
I assume youre using a Jupyter notebook? If so, put it in the first cell and all should work.
python SyntaxError: invalid syntax %matplotlib inline
%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 dont want to use jupyter notebook, you can remove %matplotlib inline from your python script and add show() at the end to display your plots.