matplotlib save animation in gif error

后端 未结 5 711
时光取名叫无心
时光取名叫无心 2020-11-29 08:58

I want to save matplotlib animation in gif format.

I succeded to save animation to mp4 format, using code

import matplotlib
matplotlib.use(\"Agg\")

         


        
5条回答
  •  孤城傲影
    2020-11-29 09:30

    Just a reminder, before you use Matplotlib and ImageMagick to convert images or videos to gif, you need to modify Matplotlib's config and add ImageMagick's path.

    The following code will show you the config file path of Matplotlib

    import matplotlib
    matplotlib.matplotlib_fname()
    

    For me the path is

    C:\Anaconda\lib\site-packages\matplotlib\mpl-data\matplotlibrc
    

    Then changing animation.convert_path

    #animation.convert_path: 'convert' # Path to ImageMagick's convert binary.
                                       # On Windows use the full path since convert
                                       # is also the name of a system tool.
    

    by adding convert.exe path to it

    animation.convert_path: C:\Program Files\ImageMagick-6.9.2-Q16-HDRI\convert.exe
    

    Don't forget to remove the # before animation.convert_path.

    After the above modification, Matplotlib and ImageMagick will perfectly work and output the gif file you want.

    example gif

    Hope it helps.

提交回复
热议问题