小编Jus*_*ess的帖子

Matplotlib无法保存动画

我有一个 matplotlib 动画,但它不会保存。如果我不保存它,它运行完全正常并且没有错误。当我尝试保存它时,会出现错误并显示一条没有帮助的消息。我已经用谷歌搜索了这个错误并检查了所有内容,但我似乎找不到这个问题的答案。我已经安装了ffmpeg。我做错了什么显而易见的事情吗?如果重要的话,我正在 ubuntu 19.10 上运行 matplotlib 3.2.1 。

保存动画的代码如下:

    def run_animation(self, total_rounds):
        anim = animation.FuncAnimation(self.fig, self.animate,
                                       init_func=self.init,
                                       frames=total_rounds * 100,
                                       interval=40,
                                       blit=True)
#        Writer = animation.writers['ffmpeg']
#        writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)
        anim.save('animation.mp4')
Run Code Online (Sandbox Code Playgroud)

错误回溯:

2020-04-01 02:20:58,279-INFO: MovieWriter._run: running command: ffmpeg -f rawvideo -vcodec rawvideo -s 1200x500 -pix_fmt rgba -r 25.0 -loglevel error -i pipe: -vcodec h264 -pix_fmt yuv420p -y animation.mp4
Traceback (most recent call last):
  File "/home/anon/.local/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 2785, in _wait_cursor_for_draw_cm
    self.set_cursor(cursors.WAIT)
  File "/home/anon/.local/lib/python3.7/site-packages/matplotlib/backends/backend_gtk3.py", line 468, in set_cursor
    self.canvas.get_property("window").set_cursor(cursord[cursor]) …
Run Code Online (Sandbox Code Playgroud)

python animation ffmpeg matplotlib gtk3

1
推荐指数
1
解决办法
2061
查看次数

标签 统计

animation ×1

ffmpeg ×1

gtk3 ×1

matplotlib ×1

python ×1