Exporting Animated Gif Using Matplotlib
Solution 1:
With the code from the question you are basically asking to produce an animated gif using the MPEG writer. The MPEG writer however is only able to produce videos.
The standard way to produce an animated gif through the matplotlib animation module is to use ImageMagick.
So first change your line to
ani.save("test.gif",writer="imagemagick")
Now for this to work the rcParam animation.convert_path
must point to the ImageMagick's convert
program.
It seems you are on windows here, so it's best to include the complete path to it. Hence, before the saving, set
plt.rcParams["animation.convert_path"] = "C:\ProgramFiles\ImageMagick\convert.exe"
or whatever your path to the convert.exe
may be.
Now it may apparently happen that convert.exe
is not part of newer versions of imageMagick anymore. The documentation says
If these tools are not available, you can simply append them to the magick tool like this:
magick convert
.
For the matplotlib animation this means that you would need to set an extra argument. Set the path to
plt.rcParams["animation.convert_path"] = "C:\ProgramFiles\ImageMagick\magick.exe"
then call
ani.save("test.gif",writer="imagemagick", extra_args="convert")
Post a Comment for "Exporting Animated Gif Using Matplotlib"