Worse_Username
Worse_Username

Reputation: 318

How to write a GIF animation to file-like buffer in matplotlib?

I'm trying to create a GIF animation and pass it as a file-like object to an API, without writing to disk. I was able to do something similar with a PNG image:

img = BytesIO(); welcome_image.save(img, 'PNG')

However, the save() method for Animation seems to expect just a file name, not a file-like object:

https://matplotlib.org/api/_as_gen/matplotlib.animation.Animation.save.html

Upvotes: 1

Views: 384

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339570

Matplotlib uses external programs like imagemagick or ffmpeg to create the animation. Those are called through a subprocess. They will require a filename to create their output to.

Only very recently the option to use pillow for creating gifs was added. With this it would theoretically be possible to do everything in memory, but as it stands this option is not available.

Upvotes: 1

Related Questions