Visualization of 3D-numpy-array frame by frame

前端 未结 2 521
花落未央
花落未央 2020-12-06 03:30
# -*- coding: utf-8 -*-
\"\"\"
slider 3D numpy array

\"\"\"

import numpy
import pylab
from matplotlib.widgets import Slider

data = numpy.random.rand(100,256,256)          


        
相关标签:
2条回答
  • 2020-12-06 03:44

    Try re-writing the update function as

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

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

    0 讨论(0)
  • 2020-12-06 04:02

    Seems like you need to cast frame number to int

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

    otherwise it will throw an error:

    l.set_data(data[frame,:,:])
    IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
    
    0 讨论(0)
提交回复
热议问题