python画地球仪_使用FFMpegwriter的Python Matplotlib底图动画在820帧之后停止?

如果我运行以下代码,它会在820帧之后停止.我在Ubuntu 12.04 VM和

Linux Mint 15上测试了这个.不幸的是没有错误消息.该程序在打印后暂停,2012-06-02T16:54:00

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

稍微解释一下代码:

我想制作一个卫星数据动画,它包含3分钟的小文件并在旋转的地球仪上显示.这就是为什么我选择在3分钟步骤中通过动画在以下示例代码步骤中创建循环.我刚刚删除了卫星数据的读取和绘图,以使任何人都可以执行代码.

当我从程序中删除底图并只绘制了随机数据的散点图时,程序一直在运行.

我不确定,但我不认为这是一个内存问题,因为我的RAM仅使用约.程序运行时为20%.

感谢您帮助我们深入了解这一点.

https://launchpad.net/~jon-severinsson/+archive/ffmpeg安装FFMPEG版本0.10.7后,它可以工作.

所以看起来这可能是libav的一个问题,默认情况下ubuntu使用它.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值