解决matplotlib.pyplot在Jupyter notebook中不显示图像问题
在代码首行添加:
%matplotlibinline
即可。
补充知识:jupyter不能显示Matplotlib动画
看莫烦老师的matplotlib教程中,有一段sinx函数动画,用Jupyter跑却不能显示动画效果。
解决方案:在前面加一句%matplotlibnotebook
动画代码如下:
%matplotlibnotebook importtensorflowastf importnumpyasnp importmatplotlib.pyplotasplt frommatplotlibimportanimation fig,ax=plt.subplots() x=np.arange(0,2*np.pi,0.01) #返回的是个列表 line,=ax.plot(x,np.sin(x)) defanimate(i): #xdata保持不变,ydata更新成另外一批数据 #将0-100都传进去更新一下,i变化时,y也会变化,更新图像 line.set_ydata(np.sin(x+i/10)) returnline, definit(): line.set_ydata(np.sin(x)) returnline, #interval是更新的频率,隔多少毫秒更新一次,这里是隔20ms更新一次 #blit=True,只更新有变化的点 ani=animation.FuncAnimation(fig=fig,func=animate,frames=100,init_func=init,interval=20,blit=False) plt.show()
以上这篇解决matplotlib.pyplot在Jupyternotebook中不显示图像问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。