In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
from JSAnimation import IPython_display
from matplotlib import animation
import JSAnimation_frametools as J

In [3]:
plotdir = '_plots'  # to store png files for each figure
J.make_plotdir(plotdir, clobber=True)  # ok to clobber if it already exists


Figure files for each frame will be stored in  _plots

In [23]:
def plot_square(t):
    x = array([-1,1,1,-1,-1])
    y = array([-1,-1,1,1,-1])
    xr = cos(t)*x + sin(t)*y
    yr = -sin(t)*x + cos(t)*y
    fill(xr,yr,'b')
    axis('scaled')
    axis([-2,2,-2,2])


num_frames = 10
for n in range(num_frames):
    t = (float(n)/num_frames) * pi/2.
    plot_square(t)
    # Save this frame:
    J.save_frame(n, plotdir,verbose=True)
    show()


Saved  _plots/frame00000.png
Saved  _plots/frame00001.png
Saved  _plots/frame00002.png
Saved  _plots/frame00003.png
Saved  _plots/frame00004.png
Saved  _plots/frame00005.png
Saved  _plots/frame00006.png
Saved  _plots/frame00007.png
Saved  _plots/frame00008.png
Saved  _plots/frame00009.png

In [24]:
anim = J.make_anim(plotdir)
anim


Out[24]:


Once Loop Reflect

In [25]:
J.make_html(anim, file_name="Square.html", title="Rotating square")


Created Square.html

In [ ]: