Python - animation with matplotlib.pyplot

前端 未结 3 816
心在旅途
心在旅途 2020-12-13 14:25

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

相关标签:
3条回答
  • 2020-12-13 14:59

    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/

    0 讨论(0)
  • 2020-12-13 15:04

    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.

    0 讨论(0)
  • 2020-12-13 15:08

    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 讨论(0)
提交回复
热议问题