IPython notebook stops evaluating cells after plt.show()

依然范特西╮ 提交于 2019-12-01 20:15:29

You should not use plt.show() in the notebook. This will open an external window that blocks the evaluation of your cell.

Instead begin your notebooks with %matplotlib inline or the cool new %matplotlib notebook (the latter is only possible with matplotlib >= 1.4.3 and ipython >= 3.0)

After the evaluation of each cell, the (still open) figure object is automatically shown in your notebook.

This minimal code example works in notebook. Note that it does not call plt.show()

%matplotlib inline
import matplotlib.pyplot as plt

x = [1,2,3]
y = [3,2,1]

_ = plt.plot(x,y)

%matplotlib inline simply displays the image.

%matplotlib notebook was added recently and offers many of the cool features (zooming, measuring,...) of the interactive backends:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!