1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01) line, = ax.plot(x, np.sin(x))
def init(): line.set_ydata([np.nan] * len(x)) return line,
def animate(i): line.set_ydata(np.sin(x + i / 100)) return line,
ani = animation.FuncAnimation( fig, animate, init_func=init, interval=2, blit=True, save_count=50)
plt.show()
|