This old post popped up while I was struggling to get some matplotlib
animations exported as an animated gif. It's not rocket science, but still somewhat of a hassle to set up the first time around. I'll leave this post for future reference.
As for the specifics when setting up this environment on a cluster, you'll have to translate each step for the specific needs for your server I guess. Animated gif is at least one of the animation options offered by the ImageMagickWriter
, but there may be more.
How-to
- Get the ImageMagick binaries
- Set an environment variable
MAGICK_HOME
pointing to the'<your-install-dir>\modules\coders'
folder (see the docs. When on windows, remember to log off and back on) point matplotlib to the install dir of ImageMagick: (mpl docs on rcParams)
import matplotlib.pyplot as plt plt.rcParams['animation.convert_path'] = '<your-install-dir>/magick.exe'
Export your animation! (mpl docs on
ImageMagickFileWriter
)writer = ImageMagickFileWriter() your_animation.save('location.gif', writer=writer)
Note that by default, errors thrown by ImageMagick will not reach you, apart from a nonzero return code. To get more extensive feedback, you'll need something like
import matplotlib as mpl
mpl.verbose.set_level("helpful")
Bonus
As a bonus, here's a proof-of-life: