3.11 Animation

Raindrop 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:

  1. import the necessary modules

  2. set up the plotting area

  3. create some data to plot

  4. plot the first line

  5. create a function to update the line

  6. 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.

3D Tulip Animation

6. Fun Examples

Last updated

Was this helpful?