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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 463 - (show annotations) (download) (as text)
Sun Apr 16 10:18:16 2006 UTC (13 years, 10 months ago) by johnpye
File MIME type: text/x-python
File size: 2060 byte(s)
Converting to the new shared-object configuration (on email discussion with Ben)
First stage: PyGTK interface on windows. More to come.
1 import config
2 import matplotlib
3 import numarray
4 matplotlib.rcParams['numerix'] = 'numarray'
5
6 import pylab
7 import platform
8 from matplotlib.colors import LinearSegmentedColormap
9
10 class IncidenceMatrixWindow:
11
12 def __init__(self,im):
13 self.im = im # IncidenceMatrix object
14 self.lastcol = None;
15 self.lastrow = None;
16
17 def run(self):
18 # convert incidence map to pylab numarray type:
19 _id = self.im.getIncidenceData();
20
21 self.data = pylab.zeros((self.im.getNumRows(), self.im.getNumCols(), ))*0.
22 for i in _id:
23 self.data[i.row, i.col] = int(i.type)
24
25 del(_id)
26
27 # prepare colour map
28 cmapdata = {
29 # type = 0 type = 1 type = 2
30 # norelation active fixed active free
31 'red' : ((0., 1., 1.), (0.5, 0., 0.), (1., 0., 0.)),
32 'green': ((0., 1., 1.), (0.5, 1., 1.), (1., 0., 0.)),
33 'blue' : ((0., 1., 1.), (0.5, 0., 0.), (1., 0.3, 0.3))
34 }
35
36 _im_cmap = LinearSegmentedColormap('im_cmap', cmapdata, 4)
37
38 pylab.ioff()
39 pylab.figure()
40 pylab.axis('equal') # aspect ratio = 1.0
41 pylab.imshow(self.data, cmap=_im_cmap, interpolation='nearest')
42 # integer 'type' values become reals 0..1, which are then coloured
43 # according to cmapdata
44 pylab.title("Incidence Matrix")
45 pylab.xlabel("Variables")
46 pylab.ylabel("Relations")
47 pylab.connect('motion_notify_event',self.on_sparsity_motion_notify)
48 pylab.ion()
49 if platform.system()=="Windows":
50 pylab.show()
51 else:
52 pylab.show(False)
53
54 def on_sparsity_motion_notify(self, event):
55 if event.xdata != None and event.ydata != None:
56 _col = int(event.xdata)
57 _row = (self.im.getNumRows()-1) - int(event.ydata)
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
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 print "rel:",_rel," var:", _var," block:",_blk
74 self.lastrow = _row;
75 self.lastcol = _col;
76

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