当前位置: 首页 > 新闻动态 > 软件编程

解决matplotlib.pyplot在Jupyter notebook中不显示图像问题

作者:用户投稿 浏览: 发布日期:2026-01-12
[导读]:这篇文章主要介绍了解决matplotlib.pyplot在Jupyter notebook中不显示图像问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

在代码首行添加:

%matplotlib inline

即可。

补充知识:jupyter不能显示Matplotlib 动画

看莫烦老师的matplotlib教程中,有一段sinx函数动画,用Jupyter跑却不能显示动画效果。

解决方案:在前面加一句%matplotlib notebook

动画代码如下:

%matplotlib notebook
import tensorflow as tf 
import numpy as np 
import matplotlib.pyplot as plt
from matplotlib import animation
fig, ax = plt.subplots()
x =np.arange(0,2*np.pi,0.01)
# 返回的是个列表
line , = ax.plot(x,np.sin(x))
def animate(i):
  # xdata 保持不变, ydata 更新成另外一批数据
  # 将0-100都传进去更新一下,i变化时,y也会变化,更新图像
  line.set_ydata(np.sin(x+i/10))
  return line,

def init():
  line.set_ydata(np.sin(x))
  return line,

# interval 是更新的频率,隔多少毫秒更新一次,这里是隔20ms更新一次
# blit=True,只更新有变化的点
ani = animation.FuncAnimation(fig=fig,func=animate,frames =100,init_func=init,interval =20,blit=False)
plt.show()

以上这篇解决matplotlib.pyplot在Jupyter notebook中不显示图像问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

免责声明:转载请注明出处:http://jing-feng.com.cn/news/760973.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!