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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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