Notebook on nbviewer (original) (raw)

JSAnimation import available at https://github.com/jakevdp/JSAnimation

from JSAnimation import IPython_display from matplotlib import animation

create a simple animation

fig = plt.figure() ax = plt.axes(xlim=(0, 10), ylim=(-2, 2)) line, = ax.plot([], [], lw=2)

x = np.linspace(0, 10, 1000)

def init(): line.set_data([], []) return line,

def animate(i): line.set_data(x, np.cos(i * 0.02 * np.pi) * np.sin(x - i * 0.02 * np.pi)) return line,

animation.FuncAnimation(fig, animate, init_func=init, frames=100, interval=20, blit=True)