# -*- coding: utf-8 -*- """ Created on Tue Feb 15 14:34:46 2011 @author: Ivo """ ''' Created on 15 feb 2011 @author: Ivo ''' import sys, time, os, gc import matplotlib matplotlib.use('WXAgg') from matplotlib import rcParams import numpy as np import matplotlib.cm as cm import matplotlib.pyplot as plt from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg from matplotlib.figure import Figure from wx import * import h5py sys.path.append("C:\\IvoPython\\PyDev\\") import data class DataCollect(object): """ This class receives a frame from the measurement and then passes it on """ def __init__(self, array3d, init = 0): self.init = init self.array3d = array3d self.maxsize = np.shape(self.array3d)[2] self.curFrame = self.init def next(self): if self.curFrame < self.maxsize: slice = self.curFrame elif self.curFrame == self.maxsize: exit(0) self.data = self.array3d[:,:,slice] self.curFrame += 1 return self.data TIMER_ID = NewId() class PlotFigure(Frame): """ This class draws a window and updates it with data from DataCollect """ def __init__(self): Frame.__init__(self, None, -1, "Test embedded wxFigure") self.fig = Figure((3,3), 75) #Varying the size of Figure has a big influence on the speed self.canvas = FigureCanvasWxAgg(self, -1, self.fig) EVT_TIMER(self, TIMER_ID, self.onTimer) def init_plot_data(self): self.datagen = DataCollect(array3d) self.axes = self.fig.add_subplot(111) self.axes.imshow(self.datagen.next().T) def onTimer(self, evt): self.data = self.datagen.next() self.axes.imshow(self.datagen.next().T) self.canvas.draw() if __name__ == '__main__': # Code required to load a measurement basedir = os.path.dirname('C:\\IvoPython\\paw-analysis\\') datafile = h5py.File(basedir+'\\data.hdf5', 'r') dog = 'Bell Oscar' for measurement in data.dogs['/' + dog]: if 'sel_1' in measurement.name: array3d = measurement.data # Code for creating a Window app = PySimpleApp() frame = PlotFigure() frame.init_plot_data() t = Timer(frame, TIMER_ID) t.Start(1) frame.Show() app.MainLoop()