@@ -1,240 +1,245 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import mpldriver |
|
2 | import mpldriver | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | class Figure: |
|
5 | class Figure: | |
6 |
|
6 | |||
7 | __driver = mpldriver |
|
7 | __driver = mpldriver | |
|
8 | fig = None | |||
8 |
|
9 | |||
9 | idfigure = None |
|
10 | idfigure = None | |
10 | wintitle = None |
|
11 | wintitle = None | |
11 | width = None |
|
12 | width = None | |
12 | height = None |
|
13 | height = None | |
13 | nplots = None |
|
14 | nplots = None | |
14 |
|
15 | |||
15 | axesObjList = [] |
|
16 | axesObjList = [] | |
16 |
|
17 | |||
17 | WIDTH = None |
|
18 | WIDTH = None | |
18 | HEIGHT = None |
|
19 | HEIGHT = None | |
19 |
|
20 | |||
20 | def __init__(self): |
|
21 | def __init__(self): | |
21 |
|
22 | |||
22 | raise ValueError, "This method is not implemented" |
|
23 | raise ValueError, "This method is not implemented" | |
23 |
|
24 | |||
|
25 | def __del__(self): | |||
|
26 | ||||
|
27 | self.__driver.closeFigure() | |||
|
28 | ||||
24 | def getAxesObjList(self): |
|
29 | def getAxesObjList(self): | |
25 |
|
30 | |||
26 | return self.axesObjList |
|
31 | return self.axesObjList | |
27 |
|
32 | |||
28 | def getSubplots(self): |
|
33 | def getSubplots(self): | |
29 |
|
34 | |||
30 | raise ValueError, "Abstract method: This method should be defined" |
|
35 | raise ValueError, "Abstract method: This method should be defined" | |
31 |
|
36 | |||
32 | def getScreenDim(self): |
|
37 | def getScreenDim(self): | |
33 |
|
38 | |||
34 | nrow, ncol = self.getSubplots() |
|
39 | nrow, ncol = self.getSubplots() | |
35 |
|
40 | |||
36 | width = self.WIDTH*ncol |
|
41 | width = self.WIDTH*ncol | |
37 | height = self.HEIGHT*nrow |
|
42 | height = self.HEIGHT*nrow | |
38 |
|
43 | |||
39 | return width, height |
|
44 | return width, height | |
40 |
|
45 | |||
41 | def init(self, idfigure, nplots, wintitle): |
|
46 | def init(self, idfigure, nplots, wintitle): | |
42 |
|
47 | |||
43 | raise ValueError, "This method has been replaced with createFigure" |
|
48 | raise ValueError, "This method has been replaced with createFigure" | |
44 |
|
49 | |||
45 | def createFigure(self, idfigure, wintitle): |
|
50 | def createFigure(self, idfigure, wintitle): | |
46 |
|
51 | |||
47 | """ |
|
52 | """ | |
48 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
53 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. | |
49 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
54 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH | |
50 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
55 | y self.HEIGHT y el numero de subplots (nrow, ncol) | |
51 |
|
56 | |||
52 | Input: |
|
57 | Input: | |
53 | idfigure : Los parametros necesarios son |
|
58 | idfigure : Los parametros necesarios son | |
54 | wintitle : |
|
59 | wintitle : | |
55 |
|
60 | |||
56 | """ |
|
61 | """ | |
57 |
|
62 | |||
58 | self.idfigure = idfigure |
|
63 | self.idfigure = idfigure | |
59 |
|
64 | |||
60 | self.wintitle = wintitle |
|
65 | self.wintitle = wintitle | |
61 |
|
66 | |||
62 | self.width, self.height = self.getScreenDim() |
|
67 | self.width, self.height = self.getScreenDim() | |
63 |
|
68 | |||
64 | self.fig = self.__driver.createFigure(self.idfigure, |
|
69 | self.fig = self.__driver.createFigure(self.idfigure, | |
65 | self.wintitle, |
|
70 | self.wintitle, | |
66 | self.width, |
|
71 | self.width, | |
67 | self.height) |
|
72 | self.height) | |
68 |
|
73 | |||
69 | self.axesObjList = [] |
|
74 | self.axesObjList = [] | |
70 |
|
75 | |||
71 | def setDriver(self, driver=mpldriver): |
|
76 | def setDriver(self, driver=mpldriver): | |
72 |
|
77 | |||
73 | self.__driver = driver |
|
78 | self.__driver = driver | |
74 |
|
79 | |||
75 | def setTitle(self, title): |
|
80 | def setTitle(self, title): | |
76 |
|
81 | |||
77 | self.__driver.setTitle(self.fig, title) |
|
82 | self.__driver.setTitle(self.fig, title) | |
78 |
|
83 | |||
79 | def setWinTitle(self, title): |
|
84 | def setWinTitle(self, title): | |
80 |
|
85 | |||
81 | self.__driver.setWinTitle(self.fig, title=title) |
|
86 | self.__driver.setWinTitle(self.fig, title=title) | |
82 |
|
87 | |||
83 | def setTextFromAxes(self, text): |
|
88 | def setTextFromAxes(self, text): | |
84 |
|
89 | |||
85 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
90 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
86 |
|
91 | |||
87 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
92 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
88 |
|
93 | |||
89 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
94 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
90 |
|
95 | |||
91 | def addAxes(self, *args): |
|
96 | def addAxes(self, *args): | |
92 | """ |
|
97 | """ | |
93 |
|
98 | |||
94 | Input: |
|
99 | Input: | |
95 | *args : Los parametros necesarios son |
|
100 | *args : Los parametros necesarios son | |
96 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
101 | nrow, ncol, xpos, ypos, colspan, rowspan | |
97 | """ |
|
102 | """ | |
98 |
|
103 | |||
99 | axesObj = Axes(self.fig, *args) |
|
104 | axesObj = Axes(self.fig, *args) | |
100 | self.axesObjList.append(axesObj) |
|
105 | self.axesObjList.append(axesObj) | |
101 |
|
106 | |||
102 | def draw(self): |
|
107 | def draw(self): | |
103 |
|
108 | |||
104 | self.__driver.draw(self.fig) |
|
109 | self.__driver.draw(self.fig) | |
105 |
|
110 | |||
106 | def run(self): |
|
111 | def run(self): | |
107 |
|
112 | |||
108 | raise ValueError, "This method is not implemented" |
|
113 | raise ValueError, "This method is not implemented" | |
109 |
|
114 | |||
110 | axesList = property(getAxesObjList) |
|
115 | axesList = property(getAxesObjList) | |
111 |
|
116 | |||
112 |
|
117 | |||
113 | class Axes: |
|
118 | class Axes: | |
114 |
|
119 | |||
115 | __driver = mpldriver |
|
120 | __driver = mpldriver | |
116 | fig = None |
|
121 | fig = None | |
117 | ax = None |
|
122 | ax = None | |
118 | plot = None |
|
123 | plot = None | |
119 |
|
124 | |||
120 | firsttime = None |
|
125 | firsttime = None | |
121 |
|
126 | |||
122 | __showprofile = False |
|
127 | __showprofile = False | |
123 |
|
128 | |||
124 | def __init__(self, *args): |
|
129 | def __init__(self, *args): | |
125 |
|
130 | |||
126 | """ |
|
131 | """ | |
127 |
|
132 | |||
128 | Input: |
|
133 | Input: | |
129 | *args : Los parametros necesarios son |
|
134 | *args : Los parametros necesarios son | |
130 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
135 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
131 | """ |
|
136 | """ | |
132 |
|
137 | |||
133 | ax = self.__driver.createAxes(*args) |
|
138 | ax = self.__driver.createAxes(*args) | |
134 | self.fig = args[0] |
|
139 | self.fig = args[0] | |
135 | self.ax = ax |
|
140 | self.ax = ax | |
136 | self.plot = None |
|
141 | self.plot = None | |
137 |
|
142 | |||
138 | self.firsttime = True |
|
143 | self.firsttime = True | |
139 |
|
144 | |||
140 | def setText(self, text): |
|
145 | def setText(self, text): | |
141 |
|
146 | |||
142 | self.__driver.setAxesText(self.ax, text) |
|
147 | self.__driver.setAxesText(self.ax, text) | |
143 |
|
148 | |||
144 | def pline(self, x, y, |
|
149 | def pline(self, x, y, | |
145 | xmin=None, xmax=None, |
|
150 | xmin=None, xmax=None, | |
146 | ymin=None, ymax=None, |
|
151 | ymin=None, ymax=None, | |
147 | xlabel='', ylabel='', |
|
152 | xlabel='', ylabel='', | |
148 | title='', |
|
153 | title='', | |
149 | **kwargs): |
|
154 | **kwargs): | |
150 |
|
155 | |||
151 | """ |
|
156 | """ | |
152 |
|
157 | |||
153 | Input: |
|
158 | Input: | |
154 | x : |
|
159 | x : | |
155 | y : |
|
160 | y : | |
156 | xmin : |
|
161 | xmin : | |
157 | xmax : |
|
162 | xmax : | |
158 | ymin : |
|
163 | ymin : | |
159 | ymax : |
|
164 | ymax : | |
160 | xlabel : |
|
165 | xlabel : | |
161 | ylabel : |
|
166 | ylabel : | |
162 | title : |
|
167 | title : | |
163 | **kwargs : Los parametros aceptados son |
|
168 | **kwargs : Los parametros aceptados son | |
164 |
|
169 | |||
165 | ticksize |
|
170 | ticksize | |
166 | ytick_visible |
|
171 | ytick_visible | |
167 | """ |
|
172 | """ | |
168 |
|
173 | |||
169 | if self.firsttime: |
|
174 | if self.firsttime: | |
170 |
|
175 | |||
171 | if xmin == None: xmin = numpy.nanmin(x) |
|
176 | if xmin == None: xmin = numpy.nanmin(x) | |
172 | if xmax == None: xmax = numpy.nanmax(x) |
|
177 | if xmax == None: xmax = numpy.nanmax(x) | |
173 | if ymin == None: ymin = numpy.nanmin(y) |
|
178 | if ymin == None: ymin = numpy.nanmin(y) | |
174 | if ymax == None: ymax = numpy.nanmax(y) |
|
179 | if ymax == None: ymax = numpy.nanmax(y) | |
175 |
|
180 | |||
176 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
181 | self.plot = self.__driver.createPline(self.ax, x, y, | |
177 | xmin, xmax, |
|
182 | xmin, xmax, | |
178 | ymin, ymax, |
|
183 | ymin, ymax, | |
179 | xlabel=xlabel, |
|
184 | xlabel=xlabel, | |
180 | ylabel=ylabel, |
|
185 | ylabel=ylabel, | |
181 | title=title, |
|
186 | title=title, | |
182 | **kwargs) |
|
187 | **kwargs) | |
183 | self.firsttime = False |
|
188 | self.firsttime = False | |
184 | return |
|
189 | return | |
185 |
|
190 | |||
186 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
191 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
187 | ylabel=ylabel, |
|
192 | ylabel=ylabel, | |
188 | title=title) |
|
193 | title=title) | |
189 |
|
194 | |||
190 |
|
195 | |||
191 | def pcolor(self, x, y, z, |
|
196 | def pcolor(self, x, y, z, | |
192 | xmin=None, xmax=None, |
|
197 | xmin=None, xmax=None, | |
193 | ymin=None, ymax=None, |
|
198 | ymin=None, ymax=None, | |
194 | zmin=None, zmax=None, |
|
199 | zmin=None, zmax=None, | |
195 | xlabel='', ylabel='', |
|
200 | xlabel='', ylabel='', | |
196 | title='', |
|
201 | title='', | |
197 | **kwargs): |
|
202 | **kwargs): | |
198 |
|
203 | |||
199 | """ |
|
204 | """ | |
200 | Input: |
|
205 | Input: | |
201 | x : |
|
206 | x : | |
202 | y : |
|
207 | y : | |
203 | x : |
|
208 | x : | |
204 | xmin : |
|
209 | xmin : | |
205 | xmax : |
|
210 | xmax : | |
206 | ymin : |
|
211 | ymin : | |
207 | ymax : |
|
212 | ymax : | |
208 | zmin : |
|
213 | zmin : | |
209 | zmax : |
|
214 | zmax : | |
210 | xlabel : |
|
215 | xlabel : | |
211 | ylabel : |
|
216 | ylabel : | |
212 | title : |
|
217 | title : | |
213 | **kwargs : Los parametros aceptados son |
|
218 | **kwargs : Los parametros aceptados son | |
214 | ticksize=9, |
|
219 | ticksize=9, | |
215 | cblabel='' |
|
220 | cblabel='' | |
216 | """ |
|
221 | """ | |
217 |
|
222 | |||
218 | if self.firsttime: |
|
223 | if self.firsttime: | |
219 |
|
224 | |||
220 | if xmin == None: xmin = numpy.nanmin(x) |
|
225 | if xmin == None: xmin = numpy.nanmin(x) | |
221 | if xmax == None: xmax = numpy.nanmax(x) |
|
226 | if xmax == None: xmax = numpy.nanmax(x) | |
222 | if ymin == None: ymin = numpy.nanmin(y) |
|
227 | if ymin == None: ymin = numpy.nanmin(y) | |
223 | if ymax == None: ymax = numpy.nanmax(y) |
|
228 | if ymax == None: ymax = numpy.nanmax(y) | |
224 | if zmin == None: zmin = numpy.nanmin(z) |
|
229 | if zmin == None: zmin = numpy.nanmin(z) | |
225 | if zmax == None: zmax = numpy.nanmax(z) |
|
230 | if zmax == None: zmax = numpy.nanmax(z) | |
226 |
|
231 | |||
227 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
232 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
228 | xmin, xmax, |
|
233 | xmin, xmax, | |
229 | ymin, ymax, |
|
234 | ymin, ymax, | |
230 | zmin, zmax, |
|
235 | zmin, zmax, | |
231 | xlabel=xlabel, |
|
236 | xlabel=xlabel, | |
232 | ylabel=ylabel, |
|
237 | ylabel=ylabel, | |
233 | title=title, |
|
238 | title=title, | |
234 | **kwargs) |
|
239 | **kwargs) | |
235 | self.firsttime = False |
|
240 | self.firsttime = False | |
236 | return |
|
241 | return | |
237 |
|
242 | |||
238 | mesh = self.__driver.pcolor(self.plot, z, xlabel=xlabel, |
|
243 | mesh = self.__driver.pcolor(self.plot, z, xlabel=xlabel, | |
239 | ylabel=ylabel, |
|
244 | ylabel=ylabel, | |
240 | title=title) |
|
245 | title=title) |
@@ -1,239 +1,246 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import matplotlib |
|
2 | import matplotlib | |
3 | matplotlib.use("TKAgg") |
|
3 | matplotlib.use("TKAgg") | |
4 | import matplotlib.pyplot |
|
4 | import matplotlib.pyplot | |
5 | #import scitools.numpyutils |
|
5 | #import scitools.numpyutils | |
6 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
6 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
7 |
|
7 | |||
8 | def init(idfigure, wintitle, width, height, facecolor="w"): |
|
8 | def init(idfigure, wintitle, width, height, facecolor="w"): | |
9 |
|
9 | |||
10 | matplotlib.pyplot.ioff() |
|
10 | matplotlib.pyplot.ioff() | |
11 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
11 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
12 | fig.canvas.manager.set_window_title(wintitle) |
|
12 | fig.canvas.manager.set_window_title(wintitle) | |
13 | fig.canvas.manager.resize(width, height) |
|
13 | fig.canvas.manager.resize(width, height) | |
14 | matplotlib.pyplot.ion() |
|
14 | matplotlib.pyplot.ion() | |
15 |
|
15 | |||
16 | return fig |
|
16 | return fig | |
17 |
|
17 | |||
18 | def setWinTitle(fig, title): |
|
18 | def setWinTitle(fig, title): | |
19 |
|
19 | |||
20 | fig.canvas.manager.set_window_title(title) |
|
20 | fig.canvas.manager.set_window_title(title) | |
21 |
|
21 | |||
22 | def setTitle(idfigure, title): |
|
22 | def setTitle(idfigure, title): | |
23 | fig = matplotlib.pyplot.figure(idfigure) |
|
23 | fig = matplotlib.pyplot.figure(idfigure) | |
24 | fig.suptitle(title) |
|
24 | fig.suptitle(title) | |
25 |
|
25 | |||
26 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
26 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): | |
27 | fig = matplotlib.pyplot.figure(idfigure) |
|
27 | fig = matplotlib.pyplot.figure(idfigure) | |
28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) |
|
28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) | |
29 | return ax |
|
29 | return ax | |
30 |
|
30 | |||
31 | def setTextFromAxes(idfigure, ax, title): |
|
31 | def setTextFromAxes(idfigure, ax, title): | |
32 | fig = matplotlib.pyplot.figure(idfigure) |
|
32 | fig = matplotlib.pyplot.figure(idfigure) | |
33 | ax.annotate(title, xy=(.1, .99), |
|
33 | ax.annotate(title, xy=(.1, .99), | |
34 | xycoords='figure fraction', |
|
34 | xycoords='figure fraction', | |
35 | horizontalalignment='left', verticalalignment='top', |
|
35 | horizontalalignment='left', verticalalignment='top', | |
36 | fontsize=10) |
|
36 | fontsize=10) | |
37 |
|
37 | |||
38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): |
|
38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): | |
39 |
|
39 | |||
40 | if firsttime: |
|
40 | if firsttime: | |
41 | ax.plot(x, y) |
|
41 | ax.plot(x, y) | |
42 | ax.set_xlim([xmin,xmax]) |
|
42 | ax.set_xlim([xmin,xmax]) | |
43 | ax.set_ylim([ymin,ymax]) |
|
43 | ax.set_ylim([ymin,ymax]) | |
44 | ax.set_xlabel(xlabel, size=8) |
|
44 | ax.set_xlabel(xlabel, size=8) | |
45 | ax.set_ylabel(ylabel, size=8) |
|
45 | ax.set_ylabel(ylabel, size=8) | |
46 | ax.set_title(title, size=10) |
|
46 | ax.set_title(title, size=10) | |
47 | matplotlib.pyplot.tight_layout() |
|
47 | matplotlib.pyplot.tight_layout() | |
48 | else: |
|
48 | else: | |
49 | ax.lines[0].set_data(x,y) |
|
49 | ax.lines[0].set_data(x,y) | |
50 |
|
50 | |||
51 | def draw(idfigure): |
|
51 | def draw(idfigure): | |
52 |
|
52 | |||
53 | fig = matplotlib.pyplot.figure(idfigure) |
|
53 | fig = matplotlib.pyplot.figure(idfigure) | |
54 | fig.canvas.draw() |
|
54 | fig.canvas.draw() | |
55 |
|
55 | |||
56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): | |
57 |
|
57 | |||
58 | if firsttime: |
|
58 | if firsttime: | |
59 | divider = make_axes_locatable(ax) |
|
59 | divider = make_axes_locatable(ax) | |
60 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
60 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
61 | fig1 = ax.get_figure() |
|
61 | fig1 = ax.get_figure() | |
62 | fig1.add_axes(ax_cb) |
|
62 | fig1.add_axes(ax_cb) | |
63 |
|
63 | |||
64 | ax.set_xlim([xmin,xmax]) |
|
64 | ax.set_xlim([xmin,xmax]) | |
65 | ax.set_ylim([ymin,ymax]) |
|
65 | ax.set_ylim([ymin,ymax]) | |
66 | ax.set_xlabel(xlabel) |
|
66 | ax.set_xlabel(xlabel) | |
67 | ax.set_ylabel(ylabel) |
|
67 | ax.set_ylabel(ylabel) | |
68 | ax.set_title(title) |
|
68 | ax.set_title(title) | |
69 | print x |
|
69 | print x | |
70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
72 | ax_cb.yaxis.tick_right() |
|
72 | ax_cb.yaxis.tick_right() | |
73 | for tl in ax_cb.get_yticklabels(): |
|
73 | for tl in ax_cb.get_yticklabels(): | |
74 | tl.set_visible(True) |
|
74 | tl.set_visible(True) | |
75 | ax_cb.yaxis.tick_right() |
|
75 | ax_cb.yaxis.tick_right() | |
76 | matplotlib.pyplot.tight_layout() |
|
76 | matplotlib.pyplot.tight_layout() | |
77 | return imesh |
|
77 | return imesh | |
78 | else: |
|
78 | else: | |
79 | # ax.set_xlim([xmin,xmax]) |
|
79 | # ax.set_xlim([xmin,xmax]) | |
80 | # ax.set_ylim([ymin,ymax]) |
|
80 | # ax.set_ylim([ymin,ymax]) | |
81 | ax.set_xlabel(xlabel) |
|
81 | ax.set_xlabel(xlabel) | |
82 | ax.set_ylabel(ylabel) |
|
82 | ax.set_ylabel(ylabel) | |
83 | ax.set_title(title) |
|
83 | ax.set_title(title) | |
84 |
|
84 | |||
85 | z = z.T |
|
85 | z = z.T | |
86 | # z = z[0:-1,0:-1] |
|
86 | # z = z[0:-1,0:-1] | |
87 | mesh.set_array(z.ravel()) |
|
87 | mesh.set_array(z.ravel()) | |
88 |
|
88 | |||
89 | return mesh |
|
89 | return mesh | |
90 |
|
90 | |||
91 | ########################################### |
|
91 | ########################################### | |
92 | #Actualizacion de las funciones del driver |
|
92 | #Actualizacion de las funciones del driver | |
93 | ########################################### |
|
93 | ########################################### | |
94 |
|
94 | |||
95 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
95 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
96 |
|
96 | |||
97 | matplotlib.pyplot.ioff() |
|
97 | matplotlib.pyplot.ioff() | |
98 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
98 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
99 | fig.canvas.manager.set_window_title(wintitle) |
|
99 | fig.canvas.manager.set_window_title(wintitle) | |
100 | fig.canvas.manager.resize(width, height) |
|
100 | fig.canvas.manager.resize(width, height) | |
101 | matplotlib.pyplot.ion() |
|
101 | matplotlib.pyplot.ion() | |
102 |
|
102 | |||
103 | return fig |
|
103 | return fig | |
104 |
|
104 | |||
|
105 | def closeFigure(): | |||
|
106 | ||||
|
107 | matplotlib.pyplot.ioff() | |||
|
108 | matplotlib.pyplot.show() | |||
|
109 | ||||
|
110 | retur | |||
|
111 | ||||
105 | def setWinTitle(fig, title): |
|
112 | def setWinTitle(fig, title): | |
106 |
|
113 | |||
107 | fig.canvas.manager.set_window_title(title) |
|
114 | fig.canvas.manager.set_window_title(title) | |
108 |
|
115 | |||
109 | def setTitle(fig, title): |
|
116 | def setTitle(fig, title): | |
110 |
|
117 | |||
111 | fig.suptitle(title) |
|
118 | fig.suptitle(title) | |
112 |
|
119 | |||
113 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
120 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
114 |
|
121 | |||
115 | matplotlib.pyplot.figure(fig.number) |
|
122 | matplotlib.pyplot.figure(fig.number) | |
116 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
123 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
117 | (xpos, ypos), |
|
124 | (xpos, ypos), | |
118 | colspan=colspan, |
|
125 | colspan=colspan, | |
119 | rowspan=rowspan) |
|
126 | rowspan=rowspan) | |
120 | return axes |
|
127 | return axes | |
121 |
|
128 | |||
122 | def setAxesText(ax, text): |
|
129 | def setAxesText(ax, text): | |
123 |
|
130 | |||
124 | ax.annotate(text, |
|
131 | ax.annotate(text, | |
125 | xy = (.1, .99), |
|
132 | xy = (.1, .99), | |
126 | xycoords = 'figure fraction', |
|
133 | xycoords = 'figure fraction', | |
127 | horizontalalignment = 'left', |
|
134 | horizontalalignment = 'left', | |
128 | verticalalignment = 'top', |
|
135 | verticalalignment = 'top', | |
129 | fontsize = 10) |
|
136 | fontsize = 10) | |
130 |
|
137 | |||
131 | def printLabels(ax, xlabel, ylabel, title): |
|
138 | def printLabels(ax, xlabel, ylabel, title): | |
132 |
|
139 | |||
133 | ax.set_xlabel(xlabel, size=11) |
|
140 | ax.set_xlabel(xlabel, size=11) | |
134 | ax.set_ylabel(ylabel, size=11) |
|
141 | ax.set_ylabel(ylabel, size=11) | |
135 | ax.set_title(title, size=12) |
|
142 | ax.set_title(title, size=12) | |
136 |
|
143 | |||
137 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
144 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
138 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
145 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
139 | nxticks=4, nyticks=10, |
|
146 | nxticks=4, nyticks=10, | |
140 | grid=None): |
|
147 | grid=None): | |
141 |
|
148 | |||
142 | """ |
|
149 | """ | |
143 |
|
150 | |||
144 | Input: |
|
151 | Input: | |
145 | grid : None, 'both', 'x', 'y' |
|
152 | grid : None, 'both', 'x', 'y' | |
146 | """ |
|
153 | """ | |
147 |
|
154 | |||
148 | ax.plot(x, y) |
|
155 | ax.plot(x, y) | |
149 | ax.set_xlim([xmin,xmax]) |
|
156 | ax.set_xlim([xmin,xmax]) | |
150 | ax.set_ylim([ymin,ymax]) |
|
157 | ax.set_ylim([ymin,ymax]) | |
151 |
|
158 | |||
152 | printLabels(ax, xlabel, ylabel, title) |
|
159 | printLabels(ax, xlabel, ylabel, title) | |
153 |
|
160 | |||
154 | ###################################################### |
|
161 | ###################################################### | |
155 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) |
|
162 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) | |
156 | ax.set_xticks(xtickspos) |
|
163 | ax.set_xticks(xtickspos) | |
157 |
|
164 | |||
158 | for tick in ax.get_xticklabels(): |
|
165 | for tick in ax.get_xticklabels(): | |
159 | tick.set_visible(xtick_visible) |
|
166 | tick.set_visible(xtick_visible) | |
160 |
|
167 | |||
161 | for tick in ax.xaxis.get_major_ticks(): |
|
168 | for tick in ax.xaxis.get_major_ticks(): | |
162 | tick.label.set_fontsize(ticksize) |
|
169 | tick.label.set_fontsize(ticksize) | |
163 |
|
170 | |||
164 | ###################################################### |
|
171 | ###################################################### | |
165 | for tick in ax.get_yticklabels(): |
|
172 | for tick in ax.get_yticklabels(): | |
166 | tick.set_visible(ytick_visible) |
|
173 | tick.set_visible(ytick_visible) | |
167 |
|
174 | |||
168 | for tick in ax.yaxis.get_major_ticks(): |
|
175 | for tick in ax.yaxis.get_major_ticks(): | |
169 | tick.label.set_fontsize(ticksize) |
|
176 | tick.label.set_fontsize(ticksize) | |
170 |
|
177 | |||
171 | ###################################################### |
|
178 | ###################################################### | |
172 | if grid != None: |
|
179 | if grid != None: | |
173 | ax.grid(b=True, which='major', axis=grid) |
|
180 | ax.grid(b=True, which='major', axis=grid) | |
174 |
|
181 | |||
175 | matplotlib.pyplot.tight_layout() |
|
182 | matplotlib.pyplot.tight_layout() | |
176 |
|
183 | |||
177 | iplot = ax.lines[-1] |
|
184 | iplot = ax.lines[-1] | |
178 |
|
185 | |||
179 | return iplot |
|
186 | return iplot | |
180 |
|
187 | |||
181 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
188 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
182 |
|
189 | |||
183 | ax = iplot.get_axes() |
|
190 | ax = iplot.get_axes() | |
184 |
|
191 | |||
185 | printLabels(ax, xlabel, ylabel, title) |
|
192 | printLabels(ax, xlabel, ylabel, title) | |
186 |
|
193 | |||
187 | iplot.set_data(x, y) |
|
194 | iplot.set_data(x, y) | |
188 |
|
195 | |||
189 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): |
|
196 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): | |
190 |
|
197 | |||
191 | divider = make_axes_locatable(ax) |
|
198 | divider = make_axes_locatable(ax) | |
192 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
199 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
193 | fig = ax.get_figure() |
|
200 | fig = ax.get_figure() | |
194 | fig.add_axes(ax_cb) |
|
201 | fig.add_axes(ax_cb) | |
195 |
|
202 | |||
196 | ax.set_xlim([xmin,xmax]) |
|
203 | ax.set_xlim([xmin,xmax]) | |
197 | ax.set_ylim([ymin,ymax]) |
|
204 | ax.set_ylim([ymin,ymax]) | |
198 |
|
205 | |||
199 | printLabels(ax, xlabel, ylabel, title) |
|
206 | printLabels(ax, xlabel, ylabel, title) | |
200 |
|
207 | |||
201 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
208 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
202 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
209 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
203 | cb.set_label(cblabel) |
|
210 | cb.set_label(cblabel) | |
204 |
|
211 | |||
205 | ax_cb.yaxis.tick_right() |
|
212 | ax_cb.yaxis.tick_right() | |
206 |
|
213 | |||
207 | for tl in ax_cb.get_yticklabels(): |
|
214 | for tl in ax_cb.get_yticklabels(): | |
208 | tl.set_visible(True) |
|
215 | tl.set_visible(True) | |
209 |
|
216 | |||
210 | for tick in ax.yaxis.get_major_ticks(): |
|
217 | for tick in ax.yaxis.get_major_ticks(): | |
211 | tick.label.set_fontsize(ticksize) |
|
218 | tick.label.set_fontsize(ticksize) | |
212 |
|
219 | |||
213 | for tick in ax.xaxis.get_major_ticks(): |
|
220 | for tick in ax.xaxis.get_major_ticks(): | |
214 | tick.label.set_fontsize(ticksize) |
|
221 | tick.label.set_fontsize(ticksize) | |
215 |
|
222 | |||
216 | for tick in cb.ax.get_yticklabels(): |
|
223 | for tick in cb.ax.get_yticklabels(): | |
217 | tick.set_fontsize(ticksize) |
|
224 | tick.set_fontsize(ticksize) | |
218 |
|
225 | |||
219 | ax_cb.yaxis.tick_right() |
|
226 | ax_cb.yaxis.tick_right() | |
220 | matplotlib.pyplot.tight_layout() |
|
227 | matplotlib.pyplot.tight_layout() | |
221 |
|
228 | |||
222 | return imesh |
|
229 | return imesh | |
223 |
|
230 | |||
224 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
231 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
225 |
|
232 | |||
226 | z = z.T |
|
233 | z = z.T | |
227 |
|
234 | |||
228 | ax = imesh.get_axes() |
|
235 | ax = imesh.get_axes() | |
229 |
|
236 | |||
230 | printLabels(ax, xlabel, ylabel, title) |
|
237 | printLabels(ax, xlabel, ylabel, title) | |
231 |
|
238 | |||
232 | imesh.set_array(z.ravel()) |
|
239 | imesh.set_array(z.ravel()) | |
233 |
|
240 | |||
234 | def draw(fig): |
|
241 | def draw(fig): | |
235 |
|
242 | |||
236 | if type(fig) == 'int': |
|
243 | if type(fig) == 'int': | |
237 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
244 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
238 |
|
245 | |||
239 | fig.canvas.draw() No newline at end of file |
|
246 | fig.canvas.draw() |
General Comments 0
You need to be logged in to leave comments.
Login now