fossekall fossekall - 7 months ago 28
Python Question

Jupyter shows plot without plt.show()

I am using the Jupyter notebook with Python 2.7. Importing matplotlib like this:

%matplotlib inline
import matplotlib.pyplot as plt


But I have observed one thing. When I use Python in Spyder I always have to use the `plt.show() commando at the end of the python script in order to see the plots.

In Jupyter I do not need this command in order to see a plot. I do get this error message:

[<matplotlib.lines.Line2D at 0x91615d0>]


but it still makes a plot. Why is that?

Answer

You turn on the immediate display with %matplotlib inline.

The line:

[<matplotlib.lines.Line2D at 0x91615d0>]

is no error message. It is the return value of the last command. Try adding a ; at the end of the last line to suppress this.

Comments