/[ascend]/trunk/pygtk/interface/incidencematrix.py
ViewVC logotype

Contents of /trunk/pygtk/interface/incidencematrix.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 260 - (show annotations) (download) (as text)
Thu Feb 2 15:31:29 2006 UTC (14 years, 2 months ago) by johnpye
File MIME type: text/x-python
File size: 1890 byte(s)
Improved behaviour of incidence matrix when you mouseover points outside the matrix
Stopped emitting exception for Block out of range (why does it happen?)
1 import pylab;
2 from matplotlib.colors import LinearSegmentedColormap
3
4 class IncidenceMatrixWindow:
5
6 def __init__(self,im):
7 self.im = im # IncidenceMatrix object
8 self.lastcol = None;
9 self.lastrow = None;
10
11 def run(self):
12 # convert incidence map to pylab numarray type:
13 _id = self.im.getIncidenceData();
14
15 self.data = pylab.zeros((self.im.getNumRows(), self.im.getNumCols(), ))*0.
16 for i in _id:
17 self.data[i.row, i.col] = int(i.type)
18
19 del(_id)
20
21 # prepare colour map
22 cmapdata = {
23 # type = 0 type = 1 type = 2
24 # norelation active fixed active free
25 'red' : ((0., 1., 1.), (0.5, 0., 0.), (1., 0., 0.)),
26 'green': ((0., 1., 1.), (0.5, 1., 1.), (1., 0., 0.)),
27 'blue' : ((0., 1., 1.), (0.5, 0., 0.), (1., 0.3, 0.3))
28 }
29
30 _im_cmap = LinearSegmentedColormap('im_cmap', cmapdata, 4)
31
32 pylab.ioff()
33 pylab.figure()
34 pylab.axis('equal') # aspect ratio = 1.0
35 pylab.imshow(self.data, cmap=_im_cmap, interpolation='nearest')
36 # integer 'type' values become reals 0..1, which are then coloured
37 # according to cmapdata
38 pylab.title("Incidence Matrix")
39 pylab.xlabel("Variables")
40 pylab.ylabel("Relations")
41 pylab.connect('motion_notify_event',self.on_sparsity_motion_notify)
42 pylab.ion()
43 pylab.show(False)
44
45 def on_sparsity_motion_notify(self, event):
46 if event.xdata != None and event.ydata != None:
47 _col = int(event.xdata)
48 _row = (self.im.getNumRows()-1) - int(event.ydata)
49
50 try:
51 if self.data[_row, _col] == 0:
52 return
53
54 if self.lastrow != None and self.lastcol != None:
55 if self.lastrow == _row and self.lastcol == _col:
56 return
57
58 _var = self.im.getVariable(_col);
59 _rel = self.im.getRelation(_row);
60 _blk = self.im.getBlockRow(_row);
61 except IndexError:
62 return
63
64 print "rel:",_rel," var:", _var," block:",_blk
65 self.lastrow = _row;
66 self.lastcol = _col;
67

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22