Animation


An animated chart displays a sequence of static charts, often in a gif or movie format. It can be really useful to describe the evolution of a dataset, or to denote the difference between two states (going from one to another and backward). This page explains how to build an animated chart with Python and Image Magick.

⏱ Quick start

An animated chart can be build with python using the following process:

  • Make a loop that outputs each step of the animation as a single chart
  • Export each chart in its own file (like png or jpg)
  • Use Image Magick to concatenate all those files into a unique .gif
Animation with python
# Use image magick to transform a set of .png in a gif
# (this is bash, not python)
# (You have to be in a folder with several images called img1.png, img2.png, img3.png...)
convert -delay 80 img*.png animation.gif

How to install Image Magick

Installing Image magick can be a nightmare. The official documentation is here. The best way to install it if you're on Mac OS is to use Homebrew as follow:

brew install imagemagick

Matplotlib logoMatplotlib and Image Magick

Let's start with a ver basic animated scatter plot made with python, matplotliband image magick. The scatter() function is used to build a scatterplot at each iteration of a loop. savefig() is used to save each chart at .png format. Finally,image magick builds the gif.

Basic animated scatterplot with python

The process is pretty much the same for a 3d chart. Here is an example with an animated volcano plot. Each iteration of the loop changes the camera angle, giving this feeling of travelling around the volcano.

Animated volcano plot with Python

💡 Animation ≠ Interaction

There is a common confusion between what animated and interactive charts are:

  • Animated means a sequence of several static images is displayed. The user can't do anything except watching those images.
  • Interactive means the user can interact with the chart: zoom in, hover over a shape to get a tooltip, click to have a menu... The user is not a spectator anymore, but also an actor.

Contact

👋 This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message onTwitter, or send an email pasting yan.holtz.data with gmail.com.

Violin

Density

Histogram

Boxplot

Ridgeline

Scatterplot

Heatmap

Correlogram

Bubble

Connected Scatter

2D Density

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Treemap

Venn Diagram

Donut

Pie Chart

Dendrogram

Circular Packing

Line chart

Area chart

Stacked Area

Streamgraph

Map

Choropleth

Hexbin

Cartogram

Connection

Bubble

Chord Diagram

Network

Sankey

Arc Diagram

Edge Bundling

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D