matplotlib:animation动画

原视频链接:https://www.bilibili.com/video/av16378354/?p=19
import numpy as np
import matplotlib
matplotlib.use(“TkAgg”)
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):
line.set_ydata(np.sin(x+i/10))

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

#frame:总共传入多少帧图像,interval:时间间隔,blit:图像的所有部分都发生变化
ani=animation.FuncAnimation(fig=fig,func=animate,frames=100,init_func=init,interval=20,blit=False)

plt.show()
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43055882/article/details/86519613
今日推荐