逐帧显示3D numpy数组 [英] Visualization of 3D-numpy-array frame by frame

查看:56
本文介绍了逐帧显示3D numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

# -*- coding: utf-8 -*-
"""
slider 3D numpy array

"""

import numpy
import pylab
from matplotlib.widgets import Slider

data = numpy.random.rand(100,256,256) #3d-array with 100 frames 256x256

ax = pylab.subplot(111)
pylab.subplots_adjust(left=0.25, bottom=0.25)

frame = 0
l = pylab.imshow(data[frame,:,:]) #shows 256x256 image, i.e. 0th frame

axcolor = 'lightgoldenrodyellow'
axframe = pylab.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
sframe = Slider(axframe, 'Frame', 0, 100, valinit=0)

def update(val):
    frame = numpy.around(sframe.val)
    pylab.subplot(111)
    pylab.subplots_adjust(left=0.25, bottom=0.25)
    pylab.imshow(data[frame,:,:])

sframe.on_changed(update)

pylab.show()

我有一个3D-numpy数组,实际上包含大小为256x256的图像.现在,我想使用滑块一个接一个地显示这些帧.它似乎真的很慢.有更好的方法吗?

I have a 3D-numpy-array, that actually contains images of size 256x256. Now I want to show these frames on after another using a slider. It appears to be really slow. Is there a better way to do that?

推荐答案

尝试将更新功能重写为

def update(val):
    frame = numpy.around(sframe.val)
    l.set_data(data[frame,:,:])

这样您就不必在每次更新时都重新创建所有matplotlib对象

so that you do not need to re-create all of the matplotlib objects every update

这篇关于逐帧显示3D numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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