在matplotlib库中更改animation.FuncAnimation中的interval参数具有意外效果 [英] Changing the interval argument in animation.FuncAnimation in the matplotlib library has unexpected effects

查看:810
本文介绍了在matplotlib库中更改animation.FuncAnimation中的interval参数具有意外效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用FuncAnimation函数时遇到一些麻烦。最紧迫的问题是将interval参数从1更改为小于1的任何值似乎对动画完全没有影响,这意味着我可以多快地运行动画。例如:

I am having a little trouble working with the FuncAnimation function. The most pressing issue is that changing the interval argument from 1 to any value less than one seems to have no effect on the animation at all, meaning that there is a limit to how fast I can run my animation. For example:

ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y[0])),
                              interval=1, blit=True, init_func=init)

运行相同

ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y[0])),
                              interval=0.01, blit=True, init_func=init)

有人有任何想法对于使用此功能的解决方法?

Does anyone have any ideas for a workaround using this function?

另一个可能相关的问题是,该功能的作用与我预期的相反。由于文档说间隔给出了帧之间的延迟(以毫秒为单位,默认为200),为什么将间隔从1倍增至2对其运行速度几乎没有影响?当然这会导致动画播放时间延长两倍吗?

Another, possibly related problem, is that the function is not acting as I expect it to anyway. Since the docs say that interval gives "Delay between frames in milliseconds. Defaults to 200.", why does doubling the interval from 1 to 2 have very little effect on the speed it runs at? Surely this should cause the animation to take twice as long to play?

感谢您的帮助。

编辑:
为了重现这一点,您可以使用此处的示例代码:
https://matplotlib.org/examples/animation/double_pendulum_animated.html

设置dt = 0.02并按时间间隔播放以查看问题。

Set dt = 0.02 and play around with the interval to see the problem.

我能想到的唯一原因是该函数不接受小于1的值,尽管这不能解释我遇到的第二个问题。

The only cause I can think of is that the function does not accept values less than 1, though this does not explain the second issue I have.

推荐答案

interval 是生成新帧的计时器间隔。然而,实际上,制作框架可能需要更长的时间。这将取决于图形的大小,要进行动画处理的数据量等。1毫秒已经相当快;至少对于通常的图形尺寸,您可能无法达到该速度,而可能会达到例如是1.7毫秒。然后,更改为2 ms不会有任何显着差异,更改为1以下的任何内容都不会有任何差异。

The interval is the timer interval at which new frames are produced. In reality, it may however take longer to produce a frame. This will depend on the figure size, the amount of data to animate etc. 1 millisecond is already quite fast; at least with usual figure sizes you probably don't reach that speed and it might instead e.g. be 1.7 ms. Then changing to 2 ms does not make any significant difference and changing to anything below 1 does not make any difference at all.

还请注意,您无法用眼睛观察到如此高的1000 fps的速度。人脑可观察的极限是〜25至30 fps的帧速率。因此,您可以只使用大约30毫秒的间隔,而不是人为地加快帧速率,而是通过 frames 参数或在动画功能内更改动画。

Also mind that you cannot observe such high speeds of 1000 fps with your eyes. The limit of what the human brain is capable of observing is a framerate of ~25 to 30 fps. So rather than artificially speeding up the framerate, you may just stick with some 30 ms interval, and instead change the animation through the frames argument or within the animating function.

这篇关于在matplotlib库中更改animation.FuncAnimation中的interval参数具有意外效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆