首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >animation.FuncAnimation地图

animation.FuncAnimation地图
EN

Stack Overflow用户
提问于 2020-05-14 13:35:31
回答 1查看 63关注 0票数 1

很抱歉,无论我使用多少示例,我都不能理解如何通过animation.FuncAnimation模块放入参数。我的任务很简单,我有地球物理数组(time,x,y)。我想要的就是让某个字段随时间变化的动画效果。我想我的函数参数应该是我的绘图函数,沿着时间轴改变索引。但它就是不会发生。

代码语言:javascript
复制
field.shape
(12,912,1125)
X,Y = np.meshgrid(lon,lat)

fig, ax = plt.subplots()
def animate(dset,i):
    ax[i] = plt.pcolormesh(X,Y,field_monthly[i].T)
    plt.colorbar()
    plt.set_cmap('viridis')
    return ax
i = np.arange(12)
anim = animation.FuncAnimation(fig, animate(field_monthly,i), frames=12, 
                               interval=500,
                               repeat=False,
                               blit=False)

我知道我的逻辑中有一些基本的漏洞,但找不到它。上面的代码是我尝试扭曲和转弯函数和索引的50种方法中的一种。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-10-06 06:11:54

在你的实现中有一些问题。

  • axi,您只有一个轴,请不要将子图与时间步长/帧相混淆
  • 使用关键字fargs来传递附加参数
  • def(i,...)第一个参数必须是更新中的颜色,而不是在开始的

中出现一次

解决这些问题:

代码语言:javascript
复制
from matplotlib import animation, pyplot as plt
import numpy as np

k, n, m = 12, 30, 50

field = np.random.random((k, n, m))
x, y = np.meshgrid(np.arange(n), np.arange(m))

fig, ax = plt.subplots()
plt.pcolormesh(x, y, field[0].T)
plt.colorbar()
plt.set_cmap('viridis')

def animate(i, field2):
    plt.cla()
    h = plt.pcolormesh(x, y, field[i].T)
    return h,

anim = animation.FuncAnimation(fig=fig, func=animate, fargs=(field,),
                               frames=k, nterval=500, repeat=False, blit=False)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61790019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档