4
如果我运行下面的代码,它只会在820帧之后停止。我在Ubuntu 12.04 VM和Linux Mint 15上都测试了这个功能。不幸的是,没有错误信息。 54:00Python Matplotlib FFMpegwriter的底图动画在820帧后停止?
import os, sys
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import matplotlib.animation as animation
from datetime import datetime,timedelta
def animation_test(start,end,fps=10,save_path='/home/username/animation_test/',\
save_name="test.mp4",dpi=80):
step = timedelta(minutes = 3)
current = start
dates =[]
frame = 0
while current <=end:
dates.append(current)
current += step
fig = plt.figure(figsize=(16,9),facecolor='k',edgecolor='k')
ax = fig.add_subplot(111)
metadata = dict(title='Movie Test', artist='Matplotlib',
comment='Movie support!')
writer = animation.FFMpegWriter(fps=fps, metadata=metadata,bitrate=20000)
direction = -0.5
lat_current = 0
lon_current = 0
with writer.saving(fig,os.path.join(save_path,save_name),dpi):
for current in dates:
ax.cla()
if direction > 0 and lat_current > 40 or \
direction < 0 and lat_current < -40:
direction = - direction
lat_current = lat_current + direction
lon_current = lon_current - 0.75
if lon_current < -180 :
lon_current += 360
basem = Basemap(projection='ortho', lat_0=lat_current, lon_0=lon_current, resolution='l',ax=ax)
basem.drawcoastlines()
#plt.show()
plt.savefig(os.path.join(save_path, 'frame%d.png'%frame),
dpi=dpi,facecolor='w',edgecolor='k')
writer.grab_frame()
frame += 1
print current.isoformat()
start = datetime.now()
animation_test(datetime(2012,6,1,0,0,0),datetime(2012,6,4,0,0,0),fps=10,dpi=80)
print datetime.now() - start
要解释代码一点点:该程序打印2012-06-02T16后只是挂 我想让它自带小3分钟文件,并显示它的卫星数据的动画在旋转的地球上。这就是为什么我选择通过动画以3分钟的步骤在以下示例代码步骤中制作循环。我只是删除了卫星数据的读取和绘图,以使代码可以被任何人执行。
当我从程序中删除底图,并绘制随机数据的散点图时,程序一直运行。
我不确定,但我不认为这是一个内存问题,因为我的RAM只使用约。在程序运行时为20%。
非常感谢您对此有所帮助。
你有什么错误吗?它是否与_just_底图运行正常? – tacaswell
可悲没有错误信息。是的,它贯穿如果我删除ffmpegwriter,如果这就是你的意思 – cpaulik
@cpaulik为了让你知道,我跑你的代码在Windows 7中,蟒蛇2.7,matplotlib 1.2.1和底图1.0.6,它的工作完美.. 。 –