【问题标题】:Saving a matplotlib animation with imagemagick, and without ffmpeg or mencoder使用 imagemagick 保存 matplotlib 动画,无需 ffmpeg 或 mencoder
【发布时间】:2014-06-18 12:13:12
【问题描述】:

我想创建一个计算函数的动画。我无法在用于运行动画的集群上安装 ffmpeg 或 mencoder,但已安装 imagemagick。 matplotlib.animation 显然支持 imagemagick 作为动画编写器(例如,参见 here)。文档说支持的格式是:

['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp', 'pbm', 'raw', 'rgba']

我认为其中有几个是非动画文件类型,但显然 ffmpeg 以某种方式支持 .sgi 文件。如果我可以在家用计算机上使用 ffmpeg 或 mencoder 转换我必须在集群器上使用的编解码器,那很好。

如何使用 imagemagick 通过 matplotlib 保存动画?

【问题讨论】:

  • 可以接受动画 gif 吗?
  • @ebarr:可以接受,但不太理想。
  • 使用您链接到的 imagemagick writer。我真的不明白你的问题,因为我认为你链接到其中的答案。
  • @tcaswell:根据文档,gif 不是受支持的格式。

标签: python animation matplotlib imagemagick sgi


【解决方案1】:

在我努力将一些matplotlib 动画导出为动画 gif 时弹出了这篇旧帖子。这不是火箭科学,但第一次设置仍然有些麻烦。我会留下这篇文章以供将来参考。

至于在集群上设置此环境时的具体细节,我猜您必须根据您的服务器的特定需求翻译每个步骤。动画 gif 至少是ImageMagickWriter 提供的动画选项之一,但可能还有更多。

操作方法

  • 获取ImageMagick 二进制文件
  • 设置环境变量MAGICK_HOME 指向'<your-install-dir>\modules\coders' 文件夹(请参阅the docs。在Windows 上时,请记住注销并重新打开)
  • 将 matplotlib 指向 ImageMagick 的安装目录:(mpl docs on rcParams)

    import matplotlib.pyplot as plt
    plt.rcParams['animation.convert_path'] = '<your-install-dir>/magick.exe'
    
  • 导出您的动画! (mpl docs on ImageMagickFileWriter)

    writer = ImageMagickFileWriter()
    your_animation.save('location.gif', writer=writer)
    

请注意,默认情况下,ImageMagick 抛出的错误不会影响您,除了返回码非零。要获得更广泛的反馈,您需要类似

import matplotlib as mpl
mpl.verbose.set_level("helpful")

奖金

作为奖励,这里有一个生命证明:

【讨论】:

  • mpl.verbose.set_level("helpful") 对我不起作用。试试mpl.rcParams['verbose.level'] = 'helpful'
【解决方案2】:

其实你可以下载 imagemagick 并编辑 matplotlibrc 来启用它

【讨论】:

  • 你能提供更多细节吗?
猜你喜欢
  • 2014-05-29
  • 2018-06-05
  • 2015-09-20
  • 2017-09-16
  • 2020-07-12
  • 2014-07-14
  • 2018-12-15
  • 1970-01-01
  • 2013-08-03
相关资源
最近更新 更多