Animating particles in a flow

This article demonstrates matplotlib's animation module by animating marker particles in a fluid flow around a cylinder. It's a bit long because it ties together a number of different ideas:

  • stream functions
  • numerical integration
  • plotting and animation

Before we really start, let's copy a function from a ...

more ...

Ragged arrays

I often need to save a series of arrays in which one dimension varies in length---sometimes called a ragged array [1]. For example, I'm running particle tracking experiments, and I need to save the 2D coordinates of all particles in each video frame. The number of particles in each ...

more ...


Plotting error bars

Let's say you have some continuous data with a continuous error (or variance) measurement. Typically, you would just call matplotlib's errorbar function:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi)
y_sin = np.sin(x)
y_cos = np.cos(x)
plt.errorbar ...
more ...

Line-color cycling

When plotting a series of lines, it's nice to pull a series of colors from a colormap (especially if there's some sequential relationship between lines). In fact, this has been asked (and answered) multiple times on the Matplotlib mailing list (e.g., [1] and [2]) and on StackOverflow ...

more ...