[英]Jupyter shows plot without plt.show()
I am using the Jupyter notebook with Python 2.7.我正在使用带有 Python 2.7 的 Jupyter 笔记本。 Importing matplotlib like this:像这样导入 matplotlib:
%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()
command at the end of the python script in order to see the plots.当我在 Spyder 中使用 Python 时,我总是必须在 Python 脚本的末尾使用plt.show()
命令才能查看绘图。
In Jupyter I do not need this command in order to see a plot.在 Jupyter 中,我不需要这个命令来查看情节。 I do get this error message:我确实收到此错误消息:
[<matplotlib.lines.Line2D at 0x91615d0>]
but it still makes a plot.但它仍然是一个情节。 Why is that?为什么?
You turn on the immediate display with %matplotlib inline
.您可以使用%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.在最后一行的末尾以抑制这一点。
The requirement of adding %matplotlin inline
is no longer needed in the latest jupyter notebooks.在最新的 jupyter 笔记本中不再需要添加%matplotlin inline
。 It's a by default addition now.现在是默认添加。
You can change settings in ipython_kernel_config.py
for different behaviour您可以针对不同的行为更改ipython_kernel_config.py
中的设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.