开发者

Python - animation with matplotlib.pyplot

How can one create animated diagrams using popular matplotlib library? I am particularly interested in 开发者_如何学Canimated gifs.


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.


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:

http://matplotlib.org/api/animation_api.html#module-matplotlib.animation

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

http://matplotlib.org/examples/animation/

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

Tutorial: http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/

Essay about visualization: http://jakevdp.github.io/blog/2013/03/23/matplotlib-and-the-future-of-visualization-in-python/


Update in 2017

Matplotlib has the animation module, and in it you find the ImageMagickFileWriter class. It is advertised as "File-based animated gif writer."

Documentation: http://matplotlib.org/api/_as_gen/matplotlib.animation.ImageMagickFileWriter.html#matplotlib.animation.ImageMagickFileWriter

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜