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

Contents of /trunk/pygtk/incidencematrix.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 729 - (show annotations) (download) (as text)
Tue Jul 4 07:05:44 2006 UTC (17 years, 10 months ago) by johnpye
File MIME type: text/x-python
File size: 2057 byte(s)
Fixed up incidence matrix so that var/rel are reported right there in the
plot window. Note sure which version of Matplotlib is required yet though.
1 import config
2 import matplotlib
3 matplotlib.use('GTKAgg')
4 import pylab
5 import platform
6 from matplotlib.colors import LinearSegmentedColormap
7
8 class IncidenceMatrixWindow:
9
10 def __init__(self,im):
11 self.im = im # IncidenceMatrix object
12 self.lastcol = None;
13 self.lastrow = None;
14
15 def run(self):
16 # convert incidence map to pylab numarray type:
17 _id = self.im.getIncidenceData();
18
19 self.data = pylab.zeros((self.im.getNumRows(), self.im.getNumCols(), ))*0.
20 for i in _id:
21 self.data[i.row, i.col] = int(i.type)
22
23 del(_id)
24
25 # prepare colour map
26 cmapdata = {
27 # type = 0 type = 1 type = 2
28 # norelation active fixed active free
29 'red' : ((0., 1., 1.), (0.5, 0., 0.), (1., 0., 0.)),
30 'green': ((0., 1., 1.), (0.5, 1., 1.), (1., 0., 0.)),
31 'blue' : ((0., 1., 1.), (0.5, 0., 0.), (1., 0.3, 0.3))
32 }
33
34 _im_cmap = LinearSegmentedColormap('im_cmap', cmapdata, 4)
35
36 pylab.ioff()
37 ax = pylab.subplot(111)
38 ax.axis('equal') # aspect ratio = 1.0
39 ax.imshow(self.data, cmap=_im_cmap, interpolation='nearest')
40 # integer 'type' values become reals 0..1, which are then coloured
41 # according to cmapdata
42 pylab.title("Incidence Matrix")
43 pylab.xlabel("Variables")
44 pylab.ylabel("Relations")
45 #pylab.connect('motion_notify_event',self.on_sparsity_motion_notify)
46 ax.format_coord = self.incidence_get_coord_str
47 pylab.ion()
48 if platform.system()=="Windows":
49 pylab.show()
50 else:
51 pylab.show(False)
52
53 def incidence_get_coord_str(self,x,y):
54
55 _col = int(x)
56 _row = (self.im.getNumRows()-1) - int(y)
57
58 try:
59 if self.data[_row, _col] == 0:
60 return ""
61
62 if self.lastrow != None and self.lastcol != None:
63 if self.lastrow == _row and self.lastcol == _col:
64 return self.lastmsg
65
66 _var = self.im.getVariable(_col);
67 _rel = self.im.getRelation(_row);
68 _blk = self.im.getBlockRow(_row);
69 except IndexError:
70 return
71
72 self.lastrow = _row;
73 self.lastcol = _col;
74 self.lastmsg = "rel '%s', var '%s': block %d" %(_rel,_var,_blk)
75 return self.lastmsg
76

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