Python Matplotlib动画未正确保存
我用pyplot制作了一个等高线场的动画,并想将其保存为电影文件。不幸的是,当我保存它时,我得到了一个正确格式的文件,我可以用VLC打开它,但它只包含一到两帧 这是我正在使用的代码的简化版本:Python Matplotlib动画未正确保存,python,animation,matplotlib,ffmpeg,Python,Animation,Matplotlib,Ffmpeg,我用pyplot制作了一个等高线场的动画,并想将其保存为电影文件。不幸的是,当我保存它时,我得到了一个正确格式的文件,我可以用VLC打开它,但它只包含一到两帧 这是我正在使用的代码的简化版本: import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation # Initialize figure and axes fig = plt.figure() ax = f
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
# Initialize figure and axes
fig = plt.figure()
ax = fig.add_subplot(111)
# Initialize mesh
x = np.r_[-5:5:100j]
X, Y = np.meshgrid(x, x)
# Computes the data and yields them
def data_generator(X, Y, dt):
for t in np.r_[:10:dt]:
yield t, np.tanh(Y*(2+t)) + np.sqrt(np.abs(X))
# Plots the given solution on the given axes
def plotter(data, ax, X, Y):
ax.clear()
t, field = data
C = ax.contour(X, Y, field)
ax.set_title('Time: {0:.1f}'.format(t))
return C
# Animation object
anim = FuncAnimation(fig, plotter, frames=data_generator(X, Y, 0.1),
interval=100, repeat=False, fargs=(ax,X,Y))
anim.save('animation.mp4')
plt.show()
我正在ArchLinux上使用
python-3.5.0
,使用matplotlib-1.5.0
。我已经安装了ffmpeg-2.8.2
。我尝试了不同的格式(例如,avi
,mkv
,mov
),还尝试了显式选择ffmpeg
和ffmpeg\u文件
编写器。问题不在于我的硬盘空间不足。我还应该检查什么?使用--debug verbose
运行脚本是否提供了任何线索?我只是这样做了,没有收到任何消息。这是一个已知错误:(它将在1.5.1中修复。解决方法是传入一个init_func
谢谢,tcaswell。我通过将一个小函数传递给构造函数来修复我的脚本:init_func=lambda:None
。使用--debug verbose
运行脚本是否提供了任何线索?我刚刚做了,没有收到任何消息。这是一个已知的bug:(它将在1.5.1中修复。解决方法是传入一个init_func
谢谢,tcaswell。我通过向构造函数传递一个普通函数来修复我的脚本:init_func=lambda:None
)。