matplotlib inline syntax error
This %matplotlib
magic is used to display graphs (of matplotlib.pyplot
objects). This needs UI to display. So cannot be display on command prompt.
According to IPython documentation,
If the
%matplotlib
magic is called without an argument, the output of a plotting command is displayed using the default matplotlib backend in a separate window. Alternatively, the backend can be explicitly requested using, for example:
%matplotlib gtk
A particularly interesting backend, provided by IPython, is the inline backend. This is available only for the Jupyter Notebook and the Jupyter QtConsole. It can be invoked as follows:
%matplotlib inline
Simple solution would be to replace %matplotlib inline
with %matplotlib
and run it using ipython
.
Alternatively, what you could do is download jupyter notebook
and run that code there.
Or as @tihom said in comments, you could comment or remove that line and run the code but this wouldn't display the graphs and other things.
pfc
Updated on July 14, 2022Comments
-
pfc almost 2 years
I'm testing a python program, which contains calling for IPython. But I got errors in the following code: If I use
%matplotlib inline
I got a syntax error at the "%" symbol. I found a solution to this problem using:
from IPython import get_ipython get_ipython().run_line_magic('matplotlib', 'inline')
I got error saying:
AttributeError: 'NoneType' object has no attribute 'run_line_magic'
I'm using Ubuntu 16.04 and running the code via command line. How can I fix this ?