无法保存matplotlib动画 [英] Can't save matplotlib animation

查看:909
本文介绍了无法保存matplotlib动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个简单的动画保存的使用ffmpeg的。我也跟着教程安装的ffmpeg,我现在可以从命令提示符访问它。

I am trying to get a simple animation saved using ffmpeg. I followed a tutorial to install ffmpeg, and I can now access it from the command prompt.

现在我经营这片code的:

Now I run this piece of code:

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation

fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)

def init():
    line.set_data([], [])
    return line,

def animate(i):
    x = np.linspace(0, 2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)
    return line,

anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=200, interval=20, blit=True)

mywriter = animation.FFMpegWriter()
anim.save('mymovie.mp4',writer=mywriter)

plt.show()

我得到这个错误:

I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
   File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 523, in runfile
    execfile(filename, namespace)
  File "C:\Users\Renger\.xy\startups\b.py", line 23, in <module>
    anim.save('mymovie.mp4',writer=mywriter)
  File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 609, in save
    with writer.saving(self._fig, filename, dpi):
  File "C:\Python27\lib\contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 166, in saving
    self.setup(*args)
  File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 156, in setup
    self._run()
  File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 183, in _run
    stdin=subprocess.PIPE)
  File "C:\Python27\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
    startupinfo)
WindowsError: [Error 2] Het systeem kan het opgegeven bestand niet vinden

最后一句荷兰是否意味着是这样的:该系统找不到指定的文件

The last dutch sentence does mean something like: The system can't find the specified file.

什么这些错误的意思是,我怎么能解决?

What do these errors mean, and how can I solve them?

推荐答案

您需要指定的ffmpeg 路径:

在linux下使用:

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
plt.rcParams['animation.ffmpeg_path'] = '/usr/bin/ffmpeg'

您显然必须指向你的Windows的exe,而不是'的/ usr / bin中/ ffmpeg的

You will obviously have to point to your windows .exe instead of '/usr/bin/ffmpeg'

如果您没有安装的ffmpeg ,则可以得到它的这里

If you don't have ffmpeg installed, you can get it here

这篇关于无法保存matplotlib动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆