Matplotlib:动画二维数组 [英] Matplotlib: Animate 2D Array

查看:275
本文介绍了Matplotlib:动画二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为2D阵列设置动画时有些麻烦:

I have some trouble to animate a 2D Array:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
arr=[]
for i in range(100):
    c=np.random.rand(10,10)        
    arr.append(c)
plt.imshow(arr[45])

我不知道如何为这个数组设置动画: https://matplotlib.org/examples/animation/dynamic_image.html

I don't get it how to animate this array like this: https://matplotlib.org/examples/animation/dynamic_image.html

感谢您度过一个愉快的周末.

Thanks have a nice weekend.

推荐答案

哦,谢谢,这比我预期的要容易.

Oh thanks, it was easyer then I expected.

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

fig = plt.figure()
i=0
im = plt.imshow(arr[0], animated=True)
def updatefig(*args):
    global i
    if (i<99):
        i += 1
    else:
        i=0
    im.set_array(arr[i])
    return im,
ani = animation.FuncAnimation(fig, updatefig,  blit=True)
plt.show()

这篇关于Matplotlib:动画二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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