Problem with "set_array" function

Hi guys,

I have a problem with the “set_array” function. In a example from the matplotlib homepage this works fine, but when I tries to adaot to my needs, the image just stays the same. No Update, but also no error messages:

see On Timer function --> the plot is just created during the start but never updated again. If I use imshow all the time, it works, but my intention was not to use imshow allover, just update the image data.

Any ideas?

Cheers,

Sebi

Here is the code:

#!/usr/bin/env python

“”"

“”"

import sys, time, os, gc

import matplotlib

matplotlib.use(‘WXAgg’)

from matplotlib import rcParams

import matplotlib.cm as cm

import numpy as np

import optparse

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg

from matplotlib.backends.backend_wx import NavigationToolbar2Wx

from matplotlib.figure import Figure

from wx import *

TIMER_ID = NewId()

class PlotFigure(Frame):

def init(self):

Frame.init(self, None, -1, “Test embedded wxFigure”)

self.fig = Figure((8,6), 100)

self.canvas = FigureCanvasWxAgg(self, -1, self.fig)

self.toolbar = NavigationToolbar2Wx(self.canvas)

self.toolbar.Realize()

On Windows, default frame size behaviour is incorrect

you don’t need this under Linux

tw, th = self.toolbar.GetSizeTuple()

fw, fh = self.canvas.GetSizeTuple()

self.toolbar.SetSize(Size(fw, th))

Create a figure manager to manage things

Now put all into a sizer

sizer = BoxSizer(VERTICAL)

This way of adding to sizer allows resizing

sizer.Add(self.canvas, 1, LEFT|TOP|GROW)

Best to allow the toolbar to resize!

sizer.Add(self.toolbar, 0, GROW)

self.SetSizer(sizer)

self.Fit()

EVT_TIMER(self, TIMER_ID, self.onTimer)

def init_plot_data(self):

initialize data array and plot for the 1st time

self.data = np.zeros([96])

create matrix which will contain the number of counted cells

well96 = np.zeros([8,12])

read in cell numbers

#Nr = 8 # number of rows

#Nc = 12 # number of columns

#labelx = [‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’,‘10’,‘11’,‘12’]

#labely = [‘A’,‘B’,‘C’,‘D’,‘E’,‘F’,‘G’,‘H’]

ax1 = self.fig.add_axes([0.075,0.1,0.75,0.85])

self.cax = self.fig.add_axes([0.85,0.1,0.075,0.85])

self.im = ax1.imshow(well96, cmap=cm.jet, interpolation=‘nearest’)

self.fig.colorbar(self.im, cax=self.cax, orientation=‘vertical’)

#self.ax1.set_xticks(np.arange(0,12,1))

#self.ax1.set_xticklabels(labelx)

#self.ax1.set_yticks(np.arange(0,8,1))

#self.ax1.set_yticklabels(labely)

#self.ax1.set_title(‘Cell Count per Well’)

def GetToolBar(self):

You will need to override GetToolBar if you are using an

unmanaged toolbar in your frame

return self.toolbar

def onTimer(self, evt):

datain = np.loadtxt(options.filename, delimiter=’;’)

self.data[0:len(datain[:,1])] = datain[:,1]

welldata = self.data.reshape(8,12)

print welldata

self.im.set_array(welldata)

#self.im = self.ax1.imshow(welldata, cmap=cm.jet, interpolation=‘nearest’)

self.fig.colorbar(self.im, cax=self.cax,orientation=‘vertical’)

self.canvas.draw()

def onEraseBackground(self, evt):

this is supposed to prevent redraw flicker on some X servers…

pass

if name == ‘main’:

configure parsing option for command line usage

parser = optparse.OptionParser()

parser.add_option(’-f’, ‘–file’,

action=“store”, dest=“filename”,

help=“query string”, default=“spam”)

read command line arguments

options, args = parser.parse_args()

print ‘Filename:’, options.filename

app = PySimpleApp()

frame = PlotFigure()

frame.init_plot_data()

Initialise the timer - wxPython requires this to be connected to

the receiving event handler

t = Timer(frame, TIMER_ID)

t.Start(1000)

frame.Show()

app.MainLoop()