简体   繁体   English

matplotlib.animation无效

[英]matplotlib.animation not working

So i've been trying to generate a dynamically updating plot that shows me several data sets as a scatter plot. 所以我一直在尝试生成动态更新的图表,向我展示几个数据集作为散点图。 I have two identically sized lists col1 and col2 containing lists in each position. 我有两个大小相同的列表col1和col2,每个位置都包含列表。 not all of these lists are equally long but len(col1[i]) = len(col2[i]) . 并非所有这些列表都相同,但len(col1[i]) = len(col2[i])

So this is what i've tried so far: 所以这就是我到目前为止所尝试的:

fig = plt.figure()
ax = fig.add_subplot(1,1,1)    
def animate(i):
        x=col1[i]
        y=col2[i]
        ax.clear()
        ax.scatter(x, y)
a = anim.FuncAnimation(fig, animate, frames=200, repeat=False)
plt.show()

When I do scatter(col1[0],col2[0]) I see the following: 当我进行scatter(col1[0],col2[0])我看到以下内容:

OUT1

and this is the first image i want to see, then the corresponding for scatter(col1[1],col2[1]) and so on. 这是我想要看到的第一个图像,然后是scatter(col1[1],col2[1])对应的scatter(col1[1],col2[1])等等。

And this is what I get every time: 这就是我每次都得到的:

产量

I notice the program is still running so I suppose the plot might still be updating with the same "image". 我注意到程序仍然在运行,所以我认为情节可能仍在使用相同的“图像”进行更新。

Am I missing something in my code? 我在代码中遗漏了什么吗?

EDIT: The second image is also what I get when I scatter plot everything together 编辑:第二张图片也是我分散绘制所有内容时得到的图像

Turns out the code is correct, I presume the image was the interval between points updating in the figurewas too fast and thus the second image is all it showed. 原来代码是正确的,我认为图像是图中更新点之间的间隔太快,因此第二个图像就是它显示的全部。

fixed by setting the interval option to 50 msecs in 通过将interval选项设置为50毫秒来修复

a = anim.FuncAnimation(fig, animate, interval=50)

(Literally replacing the line for this one fixed it.) (直接替换这个修复它的线。)

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

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