代码:
import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import animationfig, 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,ani = animation.FuncAnimation(fig=fig, func=animate, frames=100,init_func=init, interval=20, blit=False)plt.show()
如果觉得《Python 之 matplotlib (十六)Animation动画》对你有帮助,请点赞、收藏,并留下你的观点哦!