[Matplotlib-users] How to create an animation of complicated figures without writing each image to file

Jerzy Karczmarczuk jerzy.karczmarczuk at unicaen.fr
Thu May 31 13:00:45 EDT 2018


Le 31/05/2018 à 14:38, Thomas Caswell answers the query of David Ketcheson :

> If you have no control over the plotting functions, can not update the 
> artists in place, or just have a sequence of Figure objects, the best 
> approach is probably to so save each frame to png and then use an 
> external program to (eg ffmpeg) stitch them together.
>
> On Thu, May 31, 2018 at 4:57 AM David Ketcheson 
> <david.ketcheson at kaust.edu.sa <mailto:david.ketcheson at kaust.edu.sa>> 
> wrote:
>
>     I would like to create an animation from a very complicated plot. 
>     The plot is created by a lot of functions and it's not feasible
>     for me to pass back the handles to all the objects that get added
>     to the plot from all of those functions.  One approach that works
>     is to write each plot to a file and then create an animation by
>     loading the images.  Unfortunately, this doesn't look good,
>     presumably because the images are first rasterized and then the
>     resolution is altered.
>
>     So I'd like to create an animation directly from a set of figures,
>     when all I have are the figures.  I've tried to use get_children()
>     recursively to get all the artists and then use
>     animation.ArtistAnimation(), but so far this only leads to an
>     empty (blank) animation. Is it possible to do what I'm attempting?
>
But you may save your figure as SVG as well, no?
[Independently of Cairo; on a personal note: I use matplotlib under 
Anaconda on Windows 10. Cairo is a zombie, it is duly installed by 
conda, and then refuses to be imported. saying that it doesn't exist 
Anybody knows what's happening?...]

The SVG produced by Matplotlib is fairly readable, and it can be even 
edited by hand, and Inkscape accepts it without frowning.

==

If, after several troubles, you decide to pass through the 
rasterization, perhaps there is no need to save PNGs, just dump your 
figure on the internal Python canvas and to its region buffer (as string 
/ bytes), and compose using the internal numpy array combination routines.

Regards.

Jerzy Karczmarczuk
/Caen, France/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180531/3088f8e6/attachment.html>


More information about the Matplotlib-users mailing list