Animation动画

 1 import numpy as np
 2 from matplotlib import pyplot as plt
 3 from matplotlib import animation
 4 
 5 fig,ax = plt.subplots()
 6 
 7 x = np.arange(0,2*np.pi,0.01)
 8 line,=ax.plot(x,np.sin(x))
 9 
10 def animate(i):
11     line.set_ydata(np.sin(x+i/10))
12     return line,
13 
14 def init():
15     line.set_ydata(np.sin(x))
16     return line,
17 ani = animation.FuncAnimation(fig=fig,func=animate,frames=100,init_func=init,interval=20,blit=True)
18 
19 plt.show()