学习心得----matplotlib实现动态图效果

经常会用到动态图,下面给段代码供大家参考,祝大家学习愉快!

import numpy as np

import matplotlib.pyplot as plt 

from matplotlib import animation

fig,ax = plt.subplots()
x = np.arange(0,100,0.1)
line, = ax.plot(x,np.sin(x))
def animat(i):
    line.set_ydata(np.sin(x+i/100))
    return line,
def initial():
    line.set_ydata(np.sin(x))
    return line,
ani = animation.FuncAnimation(fig=fig,func=animat,frames=1000,

                              init_func=initial,interval=20,blit=True)

#frames是总帧数,interval间隔数。

plt.show()

猜你喜欢

转载自blog.csdn.net/weixin_42039090/article/details/80501973