Python - animation with matplotlib.pyplot


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

3/30/2010 4:16:12 PM

Accepted Answer

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.

7/30/2018 8:56:10 AM

This question is kind of old but nevertheless I will answer just in case someone crash here and this can be useful.

So nowadays it seems that the best way to go in matplotlib is to use the functionality that they provide:

They also include some useful examples which you can easily modify for your needs (Though the explanation on how they work will be hard to grasp if you haven't used matplotlib in a class oriented way):

Finally just to complement this information Jake VanderPlas has a more complete tutorial and a brief review on the future of visualization in Python:


Essay about visualization:

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow