Jupyter显示没有plt.show()的情节


问题内容

我正在将Jupyter笔记本与Python 2.7一起使用。像这样导入matplotlib:

%matplotlib inline    
import matplotlib.pyplot as plt

但是我观察到了一件事。当我在Spyder中使用Python时,我总是必须plt.show()在python脚本的末尾使用命令才能查看图表。

在Jupyter中,我不需要此命令即可查看绘图。我确实收到此错误消息:

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

但它仍然会阴谋。这是为什么?


问题答案:

您可以使用打开即时显示%matplotlib inline

该行:

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

是没有错误信息。它是最后一条命令的返回值。尝试;在最后一行的末尾添加a来抑制这种情况。