简体   繁体   English

FuncAnimation仅打印第一张图像

[英]FuncAnimation printing first image only

I'm trying to animate a 3D array in python using the first dimension as time. 我正在尝试使用第一个维度作为时间为python中的3D数组设置动画。

I'm not sure where I am going wrong, as I recieve no error with this code. 我不确定我要去哪里哪里,因为我没有收到这段代码的错误。 But my animation is stationary, stuck on the first page of the array. 但是我的动画是固定的,停留在数组的第一页上。

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation

array = np.random.random(size=(10, 20, 30))
empty = np.zeros(array[0].shape)

fig = plt.figure()
mat = plt.imshow(empty)
def func(i):
    mat.set_data(array[i])
    return mat
frames = len(array)
FuncAnimation(fig, func, frames)
plt.show()

I'd like the use the below code but I haven't seen an annonymous function used anywhere with FuncAnimation. 我想使用下面的代码,但没有在FuncAnimation的任何地方使用过匿名函数。 It produces the same result except mat is not created setting the initial axes . 产生相同的结果,只是未设置起始axes未创建mat

fig = plt.figure()
func = lambda i: plt.imshow(array[i])
frames = len(array)
FuncAnimation(fig, func, frames)
plt.show()

The main difference between your code and any example you find on matplotlib animations is that you do not actually store the FuncAnimation . 您的代码与在matplotlib动画中找到的任何示例之间的主要区别在于,您实际上并未存储FuncAnimation Depending on how you run things it would then directly be garbage-collected. 然后,根据运行方式的不同,将直接对其进行垃圾收集。

ani = FuncAnimation(...)

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

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