Adapted from
http://nbviewer.ipython.org/github/jakevdp/JSAnimation/blob/master/animation_example.ipynb
See http://faculty.washington.edu/rjl/classes/am583s2014/notes/animation.html.
In [ ]:
%pylab inline
In [ ]:
from JSAnimation import IPython_display
from matplotlib import animation
In [ ]:
# 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)
In [ ]: