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

Contents of /trunk/pygtk/incidencematrix.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1665 - (show annotations) (download) (as text)
Mon Dec 17 00:45:59 2007 UTC (12 years, 6 months ago) by jpye
File MIME type: text/x-python
File size: 2221 byte(s)
Refactored 'moduleview' stuff out of gtkbrowser.py.
Fixed headers of childio.h (added #include "child.h")
Fixed line-up of incidence matrix and axis tickmarks.
Module list is now sorted in library.cpp.
Added some docstrings in ascpy.i.
1 import config
2 import loading
3 import platform
4
5 try:
6 import matplotlib
7 import pylab
8 from matplotlib.colors import LinearSegmentedColormap
9 except:
10 pass
11
12 class IncidenceMatrixWindow:
13
14 def __init__(self,im):
15 self.im = im # IncidenceMatrix object
16 self.lastcol = None;
17 self.lastrow = None;
18
19 loading.load_matplotlib(throw=True)
20
21 def run(self):
22 # convert incidence map to pylab numarray type:
23 _id = self.im.getIncidenceData();
24
25 self.data = pylab.zeros((self.im.getNumRows(), self.im.getNumCols(), ))*0.
26 for i in _id:
27 self.data[i.row, i.col] = int(i.type)
28
29 del(_id)
30
31 # prepare colour map
32 cmapdata = {
33 # type = 0 type = 1 type = 2
34 # norelation active fixed active free
35 'red' : ((0., 1., 1.), (0.5, 0., 0.), (1., 0., 0.)),
36 'green': ((0., 1., 1.), (0.5, 1., 1.), (1., 0., 0.)),
37 'blue' : ((0., 1., 1.), (0.5, 0., 0.), (1., 0.3, 0.3))
38 }
39
40 _im_cmap = LinearSegmentedColormap('im_cmap', cmapdata, 4)
41
42 pylab.ioff()
43 pylab.figure()
44 ax = pylab.subplot(111)
45 ax.axis('equal') # aspect ratio = 1.0
46 ax.imshow(self.data, cmap=_im_cmap, interpolation='nearest')
47 # integer 'type' values become reals 0..1, which are then coloured
48 # according to cmapdata
49 pylab.title("Incidence Matrix")
50 pylab.xlabel("Variables")
51 pylab.ylabel("Relations")
52 #pylab.connect('motion_notify_event',self.on_sparsity_motion_notify)
53 ax.format_coord = self.incidence_get_coord_str
54 pylab.ion()
55 if platform.system()=="Windows":
56 pylab.show()
57 else:
58 pylab.show(False)
59
60 def incidence_get_coord_str(self,x,y):
61
62 _col = int(x+0.5)
63 _row = int(y+0.5)
64
65
66 try:
67 if self.data[_row, _col] == 0:
68 #print "nothing here"
69 return ""
70
71 if self.lastrow != None and self.lastcol != None:
72 if self.lastrow == _row and self.lastcol == _col:
73 return self.lastmsg
74
75 _var = self.im.getVariable(_col);
76 _rel = self.im.getRelation(_row);
77 _blk = self.im.getBlockRow(_row);
78 except IndexError:
79 return "[out of range]"
80
81 print "row = %d, col = %d" % (_row,_col)
82
83 self.lastrow = _row;
84 self.lastcol = _col;
85 self.lastmsg = "rel '%s', var '%s': block %d" %(_rel,_var,_blk)
86 print self.lastmsg
87 return self.lastmsg
88

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