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

Thomas Caswell tcaswell at gmail.com
Thu May 31 08:38:45 EDT 2018


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.  Make sure that you are not
using `bbox_inches='tight'`, tight_layour, or contrained layout (so every
saved figure is the same size and the axes are in the same place).

If you can re-use the same `Figure` object you can directly use the Writer
classes is `matplotlib.animation`, see
https://matplotlib.org/api/animation_api.html?highlight=animation#writer-classes
.
Those instances are bound to a particular Figure, you _may_ be able to just
re-set the figure (but not sure what other state we hold based on the
initial figure that might need to be updated as well), at a minimum they
should be a good starting point to write your self a "concatenate a list of
figures into a movie" writer.

Tom

On Thu, May 31, 2018 at 4:57 AM David Ketcheson <
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?
>
> -David
>
> ------------------------------
> This message and its contents including attachments are intended solely
> for the original recipient. If you are not the intended recipient or have
> received this message in error, please notify me immediately and delete
> this message from your computer system. Any unauthorized use or
> distribution is prohibited. Please consider the environment before printing
> this email.
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180531/abf7fad5/attachment.html>


More information about the Matplotlib-users mailing list