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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 254 - (hide annotations) (download) (as text)
Thu Feb 2 06:27:17 2006 UTC (14 years, 2 months ago) by johnpye
File MIME type: text/x-python
File size: 1837 byte(s)
Added reporting of unconverged variables to the console
1 johnpye 247 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     if self.data[_row, _col] == 0:
50     return
51    
52     if self.lastrow != None and self.lastcol != None:
53     if self.lastrow == _row and self.lastcol == _col:
54     return
55     _var = self.im.getVariable(_col);
56     _rel = self.im.getRelation(_row);
57     _blk = self.im.getBlockRow(_row);
58     print "rel:",_rel," var:", _var," block:",_blk
59     self.lastrow = _row;
60     self.lastcol = _col;
61 johnpye 254

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