Path: blob/master/JSAnimation/make_animation.py
934 views
import numpy as np1from matplotlib import pyplot as plt2from matplotlib import animation3from JSAnimation import HTMLWriter456fig = plt.figure(figsize=(4, 3))7ax = plt.axes(xlim=(0, 10), ylim=(-2, 2))8line, = ax.plot([], [], lw=2)910def init():11line.set_data([], [])12return line,1314def animate(i):15x = np.linspace(0, 10, 1000)16y = np.cos(i * 0.02 * np.pi) * np.sin(x - i * 0.02 * np.pi)17line.set_data(x, y)18return line,1920anim = animation.FuncAnimation(fig, animate, init_func=init,21frames=100, interval=20, blit=True)2223# set embed_frames=True to embed base64-encoded frames directly in the HTML24anim.save('animation.html', writer=HTMLWriter(embed_frames=True))252627