相关疑难解决方法(0)

无法保存与ffmpeg的matplotlib动画

我试图从Jake Vanderplas中保存一个简单的matplotlib动画,但我一直在努力OSError: [Errno 13] Permission denied.

我应该注意到,我对Jake Vanderplas的例子进行了两次小修改.我安装FFMPEG从MacPorts的,所以我增加了行plt.rcParams['animation.ffmpeg_path'] = '/opt/local/bin'和我跑进(所讨论的问题使用的FFmpeg和IPython的),所以我加入FFwriter = animation.FFMpegWriter().

这是代码:

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

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) …
Run Code Online (Sandbox Code Playgroud)

python animation matplotlib

15
推荐指数
1
解决办法
2万
查看次数

无法保存matplotlib动画

我正在尝试使用ffmpeg保存一个简单的动画.我按照教程安装ffmpeg,现在我可以从命令提示符访问它.

现在我运行这段代码:

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()
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Traceback (most recent call last):
  File "<stdin>", line …
Run Code Online (Sandbox Code Playgroud)

python animation ffmpeg matplotlib save

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

animation ×2

matplotlib ×2

python ×2

ffmpeg ×1

save ×1