Jupyter shows plot without plt.show()

2019-02-18 05:23发布

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?

1条回答
仙女界的扛把子
2楼-- · 2019-02-18 05:49

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.

查看更多
登录 后发表回答