matplotlib中的动画模块通常需要第三方模块(如FFmpeg、mencoder或imagemagik)才能将动画保存到文件中(例如:https://stackoverflow.com/a/25143651/5082048)。在
甚至matplotlib中的MovieWriter类似乎都是以第三方模块的方式构建的(启动和关闭进程,通过管道进行通信):http://matplotlib.org/api/animation_api.html#matplotlib.animation.MovieWriter。在
我正在寻找一种方法,如何将matplotlib.animation.FuncAnimation
对象帧到帧直接保存到png,在python中。然后,我想用这个方法在iPython笔记本中以动画形式显示.png文件:https://github.com/PBrockmann/ipython_animation_javascript_tool/
因此,我的问题是:
matplotlib.animation.FuncAnimation
对象直接保存到.png文件而不需要使用第三方模块?在编辑:给出了matplotlib.animation.FuncAnimation
对象,任务是使用纯Python保存它的帧。不幸的是,我不能像ImportanceOfBeingErnest建议的那样更改底层动画函数。在
你想看一下
FileMovieWriter
子类(参见http://matplotlib.org/2.0.0rc2/api/animation_api.html#writer-classes),你可能想把FileMoveWriter
分成子类,比如(这是不测试的,最好只实现一个实现
saving
、grab_frame
、finished
和setup
的类)尽管这看起来有点复杂,但保存动画的帧在动画本身中可能很容易完成。在
注意
repeat = False
参数,这将阻止动画连续运行并重复将相同的文件写入磁盘。在请注意,如果您愿意放宽“无外部软件包”的限制,您可以使用imagemagick保存PNG
^{pr2}$这将保存文件anim-1.png、anim-2.png等
最后注意,当然有easier methods to show an animation in a jupyter notebook。在
我无法得到塔卡斯威尔的答复,不加修改。所以,这是我的看法。在
我们可以用以下方式保存一组文件:
^{pr2}$它将以“filename{number}.format”的形式保存文件。在
相关问题 更多 >
编程相关推荐