简体   繁体   English

如何在 python matplotlib animation 中指定开始时间?

[英]How to specify start time in a python matplotlib animation?

I am animating a time series that has 3600 timesteps.我正在为具有 3600 个时间步长的时间序列制作动画。 I only want to plot timestep 1200 to 1800 in an animation, however I can only get the animation to run from the very first time step onwards.我只想在 animation 中的 plot 时间步长 1200 到 1800,但是我只能让 animation 从一开始就运行。 Below is a simplified version of what I've been trying.下面是我一直在尝试的简化版本。

sal = ax1.contourf(X[:,:,1200],Y[:,:,1200],Z[:,:,1200]),100)

def animate(i):
    sal = ax1.contourf(X[:,:,i],Y[:,:,i],Z[:,:,i]),100)

anim = FuncAnimation(f, animate, interval=100, frames=len(Seconds[1200:1800]))

The above still starts from 0. I want to be able to specify a starting index of 1200 not 0.上面还是从 0 开始。我希望能够指定 1200 而不是 0 的起始索引。

len(Seconds[1200:1800]) returns gives a single value 600 , and according to the docs passing an int to frames is the same passing range(x) . len(Seconds[1200:1800])返回给出单个值600 ,并且根据文档int传递给frames是相同的传递range(x) So I think your just animating just the first 600 frames.所以我认为你只是为前 600 帧设置动画。 Try尝试

anim = FuncAnimation(f, animate, interval=100, frames=range(1200,1800))

and let me know if it works!让我知道它是否有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM