显示与imshow连续图像/阵列作为蟒蛇重复动画 [英] Show consecutive images/arrays with imshow as repeating animation in python

查看:756
本文介绍了显示与imshow连续图像/阵列作为蟒蛇重复动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经计算了一些结果,它们是在64×64的阵列的形式。每个阵列创建后,其他一些时间。我想显示这些阵列一前一后,象动画。
我已经尝试了很多方法,并得到了没有工作。林感到相当沮丧和SO关于动画的问题一直没能帮助我得到这个工作。这不是我第一次尝试这个,每次我的结果是一样的,虽然:我从来没有得到这个工作。

I have calculated some results and they are in the form of 64x64 arrays. Each array is created some time after the other. I want to show these arrays one after the other, like an animation. I have tried many ways, and got none to work. Im am quite frustrated and the questions on SO regarding animations have not been able to help me get this to work. This is not the first time I try this, every time my result is the same though: I have never gotten this to work.

我已经试过的方法:

动态图片

动态影像2

简单的动画

目前的code我有:

fig, ax = plt.subplots()
def animate(i):
    return imagelist[i] 
def init():
    fig.set_data([],[])
    return fig
ani = animation.FuncAnimation(fig, animate, np.arange(0, 19), init_func=init,
interval=20, blit=True)
plt.show()

下面是图像列表我上面提到的阵列(长度为20,0至19)的列表。我的问题是我怎么能得到这个工作?

Here imagelist is a list of the arrays I mention above (length 20, 0 through 19). My question is how can I get this to work?

推荐答案

复制从您首先几乎一模一样链接(和添加一些评论)

Copying almost exactly from your first link (and adding some comments):

hmpf = ones([4,4])
hmpf[2][1] = 0
imagelist = [ hmpf*i*255./19. for i in range(20) ]

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure() # make figure

# make axesimage object
# the vmin and vmax here are very important to get the color map correct
im = plt.imshow(imagelist[0], cmap=plt.get_cmap('jet'), vmin=0, vmax=255)

# function to update figure
def updatefig(j):
    # set the data in the axesimage object
    im.set_array(imagelist[j])
    # return the artists set
    return im,
# kick off the animation
ani = animation.FuncAnimation(fig, updatefig, frames=range(20), 
                              interval=50, blit=True)
plt.show()

这个动画如我所料

这篇关于显示与imshow连续图像/阵列作为蟒蛇重复动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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