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

Contents of /trunk/pygtk/incidencematrix.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1387 - (show annotations) (download) (as text)
Sat Apr 7 14:43:31 2007 UTC (13 years, 9 months ago) by jpye
File MIME type: text/x-python
File size: 2074 byte(s)
Added plot support in Integrator output tabs.
Some other minor debugging for pylab integration and idaanalyse output.
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 pylab.figure()
38 ax = pylab.subplot(111)
39 ax.axis('equal') # aspect ratio = 1.0
40 ax.imshow(self.data, cmap=_im_cmap, interpolation='nearest')
41 # integer 'type' values become reals 0..1, which are then coloured
42 # according to cmapdata
43 pylab.title("Incidence Matrix")
44 pylab.xlabel("Variables")
45 pylab.ylabel("Relations")
46 #pylab.connect('motion_notify_event',self.on_sparsity_motion_notify)
47 ax.format_coord = self.incidence_get_coord_str
48 pylab.ion()
49 if platform.system()=="Windows":
50 pylab.show()
51 else:
52 pylab.show(False)
53
54 def incidence_get_coord_str(self,x,y):
55
56 _col = int(x)
57 _row = (self.im.getNumRows()-1) - int(y)
58
59 try:
60 if self.data[_row, _col] == 0:
61 return ""
62
63 if self.lastrow != None and self.lastcol != None:
64 if self.lastrow == _row and self.lastcol == _col:
65 return self.lastmsg
66
67 _var = self.im.getVariable(_col);
68 _rel = self.im.getRelation(_row);
69 _blk = self.im.getBlockRow(_row);
70 except IndexError:
71 return
72
73 self.lastrow = _row;
74 self.lastcol = _col;
75 self.lastmsg = "rel '%s', var '%s': block %d" %(_rel,_var,_blk)
76 return self.lastmsg
77

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