Jupyter显示没有plt.show()的情节 [英] Jupyter shows plot without plt.show()
问题描述
我正在将Jupyter笔记本与Python 2.7一起使用.像这样导入matplotlib:
I am using the Jupyter notebook with Python 2.7. Importing matplotlib like this:
%matplotlib inline
import matplotlib.pyplot as plt
但是我观察到一件事.当我在Spyder中使用Python时,我总是必须在python脚本的末尾使用plt.show()
命令才能查看图.
But I have observed one thing. When I use Python in Spyder I always have to use the plt.show()
command at the end of the python script in order to see the plots.
在Jupyter中,我不需要此命令即可查看情节.我确实收到此错误消息:
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?
推荐答案
您可以使用%matplotlib inline
打开即时显示.
You turn on the immediate display with %matplotlib inline
.
该行:
[<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.
这篇关于Jupyter显示没有plt.show()的情节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!