On 6/26/07, Jason Addison <[EMAIL PROTECTED]> wrote:
I would like to view a 3D array (or a python list of 2D arrays) as a
sequence of images using something like imshow. For example, something
like this:

imshow(rand(6,12,12), imagecube=true)


Here is a simple example showing how to do this -- we could add
support for this in a built-in function.  It would be nice if we
encapsulated the scroll mouse in our event handling, since the scroll
is the natural way to browse these images


from pylab import figure, show




class IndexTracker:
   def __init__(self, ax, X):
       self.ax = ax
       ax.set_title('use left mouse to advance, right to retreat')

       self.X = X
       rows,cols,self.slices = X.shape
       self.ind  = self.slices/2

       self.im = ax.imshow(self.X[:,:,self.ind])
       self.update()

   def onpress(self, event):

       if event.button==1:
           self.ind = numpy.clip(self.ind+1, 0, self.slices-1)
       elif event.button==3:
           self.ind = numpy.clip(self.ind-1, 0, self.slices-1)

       print event.button, self.ind
       self.update()

   def update(self):
       self.im.set_data(self.X[:,:,self.ind])
       ax.set_ylabel('slice %s'%self.ind)
       self.im.axes.figure.canvas.draw()


fig = figure()
ax = fig.add_subplot(111)

X = numpy.random.rand(20,20,40)

tracker = IndexTracker(ax, X)



fig.canvas.mpl_connect('button_press_event', tracker.onpress)

show()
import numpy
from pylab import figure, show




class IndexTracker:
    def __init__(self, ax, X):
        self.ax = ax
        ax.set_title('use left mouse to advance, right to retreat')

        self.X = X
        rows,cols,self.slices = X.shape
        self.ind  = self.slices/2

        self.im = ax.imshow(self.X[:,:,self.ind])
        self.update()

    def onpress(self, event):

        if event.button==1:
            self.ind = numpy.clip(self.ind+1, 0, self.slices-1)
        elif event.button==3:
            self.ind = numpy.clip(self.ind-1, 0, self.slices-1)

        print event.button, self.ind
        self.update()

    def update(self):
        self.im.set_data(self.X[:,:,self.ind])
        ax.set_ylabel('slice %s'%self.ind)        
        self.im.axes.figure.canvas.draw()


fig = figure()
ax = fig.add_subplot(111)

X = numpy.random.rand(20,20,40)

tracker = IndexTracker(ax, X)



fig.canvas.mpl_connect('button_press_event', tracker.onpress)

show()
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to