This notebook demonstrates the tools in the
clawpack.visclaw.animation_tools module (new in Version 5.4.0), which facilitates creating a list of figures or images and viewing them as an animation.
This notebook can be found in
$CLAW/apps/notebooks/visclaw, see http://www.clawpack.org/apps.html for instructions for cloning the Clawpack
Several approaches are supported:
ipywidgets.interact allows generating an interactive widget for sweeping through the frames. This may be easiest to work with when running a notebook interactively, including when using http://mybinder.org.
JSAnimation package from https://github.com/jakevdp/JSAnimation creates animations with controls that allow viewing as a movie more easily. You can also create a stand-alone html file of an animation to post on the web. Moreover movies created with JSAnimation and saved with the notebook will operate properly when viewed via
JSAnimation version can also be embedded in another webpage or in Sphinx documentation, using the
mp4 file can also be created using the
_plotsdirectory to animations:¶
The script make_anim.py illustrates how to turn the png files in a Clawpack
_plots directory into stand-alone
Populating the interactive namespace from numpy and matplotlib
from __future__ import print_function from ipywidgets import interact, interact_manual import ipywidgets import os import io import base64 from IPython.display import display, FileLink, FileLinks, HTML
from clawpack.visclaw import animation_tools
figs =  x = linspace(0,1,1000) for k in range(11): fig = figure(figsize=(5,3)) plot(x, sin(2*pi*k*x), 'b') ylim(-1.1,1.1) title('$\sin(2\pi kx)$ for k = %s' % k) figs.append(fig) close(fig)
Passing in the argument
manual=True will use the widget
interact_manual instead of
interact. This refrains from updating the image as you move the slider bar. Instead you move the slider as desired and then click on the
Run button to re-display the image. This is useful if there are many frames and you want to be able to jump to around without all the intermediate frames being displayed, which can slow down the response significantly.
TextInput=True can be specified to produce a text input cell rather than a slider bar:
animation_tools.interact_animate_figs(figs, manual=True, TextInput=True)
Valid frameno values: from 0 to 10
animation_tools.interact_animate_images can be used to create an interact that loops over all the frames contained in a list of images rather than figures. The images can be generated from a list of figures, as illustrated in the next cell. Or they can be read in from a directory of png files, for example, as illustrated later.
This function also takes the arguments
TextInput as described above, with default values
images = animation_tools.make_images(figs) animation_tools.interact_animate_images(images, figsize=(6,3))