如何创建不确定的funcanimation帧实时动态更新? [英] How to create indefinite funcanimation frames dynamically updating in real time?

查看:578
本文介绍了如何创建不确定的funcanimation帧实时动态更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新创建



问题是,执行时间与次数成正比,然后生成图形。因此,如果大于或等于1000,则生成图形需要花费大量时间。看起来它在输出图形之前会生成所有1000帧。这样,我至少需要约20000帧。取而代之的是,只要打开网站或设置为无编译时损害的上限,它就应该处于活动状态并进行更新。



下一个问题是1000 ,计数器重新开始。全球计数器是否应该继续增加?



我想要


  1. 程序立即启动,然后像在我引用的例子。

  2. 程序在帧计数结束后继续增加计数器或不重置变量。如果不是 matplotlib ,seaborn或 plotly 或任何其他lib可以在这里提供帮助?

我在 ipython笔记本(anaconda环境)中使用Python 3.x 。

解决方案

ani.to_html5_video()创建一个文件。为了创建该文件,需要事先知道所有框架。因此,动画完整运行一次,然后保存这些帧并将其转换为html5视频。



如果要实时观看动画,可以使用%matplotlib笔记本后端而不保存动画。



对于1000帧,您要在第三个参数中自己将该数字设置为 FuncAnimation np.arange(1,1000)。删除该参数或在此处选择其他数字,例如帧= 20000


I am trying to recreate a population variance graph in python

In that example, as soon as we start, the function runs immediately to I guess the limit of the environment set by the website.

I have managed to create similar graphs, but for animation I am stuck. Below is my code.

import matplotlib.animation as animation

fig, ax = plt.subplots(1,1,figsize=(5,4))
plt.close()

frameRate = 30

global_counter = 0

def animate(i):

    ax.clear()

    global global_counter

    ax.text(0.5,0.5, 'test:{}'.format(global_counter))
    global_counter += 1


ani = animation.FuncAnimation(fig, animate, np.arange(1,1000), interval=frameRate)

plt.tight_layout()
from IPython.display import HTML
HTML(ani.to_html5_video())

Output:

The problem is, the execution time is directly proportional to the number of times and then the graph is generated. So if 1000 as above or more, it takes considerable time before generating the graph. Looks like it generates all 1000 frames before outputting the graph. I would need about at least 20000 frames this way. Instead, it should be live and update as long as the website is opened or to an upper limit set without compile-time compromise.

And the next problem is, after 1000, the counter starts all over again. Shouldn't the global counter continue to increase?

I want

  1. Program to start immediately and then update dynamically like in the example I quoted.
  2. Program to continue increasing counter or not resetting variables after frames count is over. If not matplotlib, seaborn or plotly or any other lib could help here?

I am using Python 3.x in ipython notebook (anaconda environment).

解决方案

ani.to_html5_video() creates a file. For this file to be created, all frames need to be known in advance. Hence the animation is run once in completeness, then those frames are saved and converted to html5 video.

If you want to see the animation live, you may use the %matplotlib notebook backend without saving the animation.

As for the 1000 frames, you are setting that number yourself in the third argument to FuncAnimation, np.arange(1,1000). Either remove that argument or chose a different number here, e.g. frames =20000.

这篇关于如何创建不确定的funcanimation帧实时动态更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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