IPython notebook stops evaluating cells after plt.show()

前端 未结 1 981
南笙
南笙 2021-01-20 05:12

I am using iPython to do some coding. When I open the notebook and run some codes by doing SHIFT+ENTER it runs. But after one or two times, it stops giving any output. Why i

相关标签:
1条回答
  • 2021-01-20 05:42

    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. inline

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

    webagg

    0 讨论(0)
提交回复
热议问题