Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - animation with matplotlib.pyplot

Tags:

How can one create animated diagrams using popular matplotlib library? I am particularly interested in animated gifs.

like image 800
psihodelia Avatar asked Mar 30 '10 16:03

psihodelia


People also ask

Can you create animations in Python?

You can create animations in Python by calling a plot function inside of a loop (usually a for-loop). The main tools for making animations in Python is the matplotlib. animation. Animation base class, which provides a framework around which the animation functionality is built.

How do you dynamically plot in Python?

To dynamically update plot in Python matplotlib, we can call draw after we updated the plot data. to define the update_line function. In it, we call set_xdata to set the data form the x-axis. And we call set_ydata to do the same for the y-axis.


1 Answers

The matplotlib docs provide an entire section of examples on animation (see this scipy tutorial also). Most, however, involve using the various GUI widget backends. There is one in there, "movie demo", that shows how to produce an avi of a series of PNGS.

To produce animated GIFs, I think your options are pretty limited. Last I checked, PIL didn't support them. You could however generate a series of PNGs using pyplot's savefig and then stitch them together using a call to ImageMagick or mencoder.

like image 151
Mark Avatar answered Oct 18 '22 19:10

Mark