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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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