3.11 Animation

1. Why Animation?
Exploring datasets is a big part of what many scientists do these days. In many cases, these datasets will have more than two dimensions. For example, temperature or salinity in an ocean circulation model has four dimensions: x, y, z, t. It’s futile to try and display these in a single plot. That’s where animation can help.
2. Animations in matplotlib
Matplotlib’s animation deals with the animation part. It provides a framework around which the animation functionality is built. There are two main interfaces to achieve that using:
FuncAnimation: makes an animation by repeatedly calling a function func. It is the most convenient one to use.
ArtistAnimation: Animation using a fixed set of Artist objects.
3. Basic Animation
An animation in six steps:
import the necessary modules
set up the plotting area
create some data to plot
plot the first line
create a function to update the line
call FuncAnimation and show

4. Subplots Animation
We can use Celluloid to simplify the process of creating animations in matplotlib. It creates a figure and creates a camera. Then it reuses figure and after each frame is created, take a snapshot with the camera. Finally, an animation is created with all the captured frames.

5. 3D Animation
Let's draw a 3D tulip this time.

6. Fun Examples

Last updated
Was this helpful?