使用 imshow 将连续图像/数组显示为 python 中的重复动画 [英] Show consecutive images/arrays with imshow as repeating animation in python

查看:37
本文介绍了使用 imshow 将连续图像/数组显示为 python 中的重复动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计算了一些结果,它们是 64x64 数组的形式.每个数组都在某个时间之后创建.我想一个接一个地显示这些数组,就像动画一样.我尝试了很多方法,都没有奏效.我很沮丧,关于动画的 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

简单动画

我拥有的当前代码:

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()

这里的 imagelist 是我上面提到的数组的列表(长度为 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?

推荐答案

我实现了一个方便的脚本,正好适合您的需要.试试看这里

I implemented a handy script that just suits your need. Try it out here

例如:

imagelist = YOUR-IMAGE-LIST
def redraw_fn(f, axes):
    img = imagelist[f]
    if not redraw_fn.initialized:
        redraw_fn.im = axes.imshow(img, animated=True)
        redraw_fn.initialized = True
    else:
        redraw_fn.im.set_array(img)
redraw_fn.initialized = False

videofig(len(imagelist), redraw_fn, play_fps=30)

这篇关于使用 imshow 将连续图像/数组显示为 python 中的重复动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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