import numpy as np
from matplotlib import 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 / 100))
return line,
def init():
line.set_ydata(np.sin(x))
return line,
# fig传入动画的对象, func
# frames传入总帧数 init_func传入初始帧
# interval传入刷新频率 blit:是否只更新发生变化的点位
ani = animation.FuncAnimation(fig=fig, func=animate, frames=100,
init_func=init, interval=20, blit=False)
plt.show()
P17-Animation 动画
最新推荐文章于 2024-07-24 23:49:50 发布