@@ -1,382 +1,382 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import sys |
|
4 | 4 | import matplotlib |
|
5 | 5 | |
|
6 | 6 | if 'linux' in sys.platform: |
|
7 | 7 | matplotlib.use("TKAgg") |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 | 10 | matplotlib.use("TKAgg") |
|
11 | 11 | |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
|
14 | 14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
15 | 15 | from matplotlib.ticker import * |
|
16 | 16 | |
|
17 | 17 | ########################################### |
|
18 | 18 | #Actualizacion de las funciones del driver |
|
19 | 19 | ########################################### |
|
20 | 20 | |
|
21 | 21 | def createFigure(idfigure, wintitle, width, height, facecolor="w", show=True): |
|
22 | 22 | |
|
23 | 23 | matplotlib.pyplot.ioff() |
|
24 | 24 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
25 | 25 | fig.canvas.manager.set_window_title(wintitle) |
|
26 | 26 | fig.canvas.manager.resize(width, height) |
|
27 | 27 | matplotlib.pyplot.ion() |
|
28 | 28 | if show: |
|
29 | 29 | matplotlib.pyplot.show() |
|
30 | 30 | |
|
31 | 31 | return fig |
|
32 | 32 | |
|
33 | 33 | def closeFigure(show=True): |
|
34 | 34 | |
|
35 | 35 | matplotlib.pyplot.ioff() |
|
36 | 36 | if show: |
|
37 | 37 | matplotlib.pyplot.show() |
|
38 | 38 | |
|
39 | 39 | return |
|
40 | 40 | |
|
41 | 41 | def saveFigure(fig, filename): |
|
42 | 42 | |
|
43 | 43 | matplotlib.pyplot.ioff() |
|
44 | 44 | fig.savefig(filename) |
|
45 | 45 | matplotlib.pyplot.ion() |
|
46 | 46 | |
|
47 | 47 | def setWinTitle(fig, title): |
|
48 | 48 | |
|
49 | 49 | fig.canvas.manager.set_window_title(title) |
|
50 | 50 | |
|
51 | 51 | def setTitle(fig, title): |
|
52 | 52 | |
|
53 | 53 | fig.suptitle(title) |
|
54 | 54 | |
|
55 | 55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
56 | 56 | |
|
57 | 57 | matplotlib.pyplot.ioff() |
|
58 | 58 | matplotlib.pyplot.figure(fig.number) |
|
59 | 59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
60 | 60 | (xpos, ypos), |
|
61 | 61 | colspan=colspan, |
|
62 | 62 | rowspan=rowspan) |
|
63 | 63 | |
|
64 | 64 | matplotlib.pyplot.ion() |
|
65 | 65 | return axes |
|
66 | 66 | |
|
67 | 67 | def setAxesText(ax, text): |
|
68 | 68 | |
|
69 | 69 | ax.annotate(text, |
|
70 | 70 | xy = (.1, .99), |
|
71 | 71 | xycoords = 'figure fraction', |
|
72 | 72 | horizontalalignment = 'left', |
|
73 | 73 | verticalalignment = 'top', |
|
74 | 74 | fontsize = 10) |
|
75 | 75 | |
|
76 | 76 | def printLabels(ax, xlabel, ylabel, title): |
|
77 | 77 | |
|
78 | 78 | ax.set_xlabel(xlabel, size=11) |
|
79 | 79 | ax.set_ylabel(ylabel, size=11) |
|
80 | 80 | ax.set_title(title, size=12) |
|
81 | 81 | |
|
82 | 82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
83 | 83 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
84 | 84 | nxticks=4, nyticks=10, |
|
85 | 85 | grid=None): |
|
86 | 86 | |
|
87 | 87 | """ |
|
88 | 88 | |
|
89 | 89 | Input: |
|
90 | 90 | grid : None, 'both', 'x', 'y' |
|
91 | 91 | """ |
|
92 | 92 | |
|
93 | 93 | matplotlib.pyplot.ioff() |
|
94 | 94 | |
|
95 | 95 | ax.set_xlim([xmin,xmax]) |
|
96 | 96 | ax.set_ylim([ymin,ymax]) |
|
97 | 97 | |
|
98 | 98 | printLabels(ax, xlabel, ylabel, title) |
|
99 | 99 | |
|
100 | 100 | ###################################################### |
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
101 | if (xmax-xmin)<=1: | |
|
102 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
|
103 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
|
104 | ax.set_xticks(xtickspos) | |
|
105 | else: | |
|
106 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
|
107 | ax.set_xticks(xtickspos) | |
|
108 | ||
|
109 | for tick in ax.get_xticklabels(): | |
|
110 | tick.set_visible(xtick_visible) | |
|
111 | ||
|
112 | for tick in ax.xaxis.get_major_ticks(): | |
|
113 | tick.label.set_fontsize(ticksize) | |
|
114 | 114 | |
|
115 | 115 | ###################################################### |
|
116 | 116 | for tick in ax.get_yticklabels(): |
|
117 | 117 | tick.set_visible(ytick_visible) |
|
118 | 118 | |
|
119 | 119 | for tick in ax.yaxis.get_major_ticks(): |
|
120 | 120 | tick.label.set_fontsize(ticksize) |
|
121 | 121 | |
|
122 | 122 | ax.plot(x, y) |
|
123 | 123 | iplot = ax.lines[-1] |
|
124 | 124 | |
|
125 | 125 | ###################################################### |
|
126 | 126 | if '0.' in matplotlib.__version__[0:2]: |
|
127 | 127 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
128 | 128 | return iplot |
|
129 | 129 | |
|
130 | 130 | if '1.0.' in matplotlib.__version__[0:4]: |
|
131 | 131 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
132 | 132 | return iplot |
|
133 | 133 | |
|
134 | 134 | if grid != None: |
|
135 | 135 | ax.grid(b=True, which='major', axis=grid) |
|
136 | 136 | |
|
137 | 137 | matplotlib.pyplot.tight_layout() |
|
138 | 138 | |
|
139 | 139 | matplotlib.pyplot.ion() |
|
140 | 140 | |
|
141 | 141 | return iplot |
|
142 | 142 | |
|
143 | 143 | def set_linedata(ax, x, y, idline): |
|
144 | 144 | |
|
145 | 145 | ax.lines[idline].set_data(x,y) |
|
146 | 146 | |
|
147 | 147 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
148 | 148 | |
|
149 | 149 | ax = iplot.get_axes() |
|
150 | 150 | |
|
151 | 151 | printLabels(ax, xlabel, ylabel, title) |
|
152 | 152 | |
|
153 | 153 | set_linedata(ax, x, y, idline=0) |
|
154 | 154 | |
|
155 | 155 | def addpline(ax, x, y, color, linestyle, lw): |
|
156 | 156 | |
|
157 | 157 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
158 | 158 | |
|
159 | 159 | |
|
160 | 160 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
161 | 161 | xlabel='', ylabel='', title='', ticksize = 9, |
|
162 | 162 | colormap='jet',cblabel='', cbsize="5%", |
|
163 | 163 | XAxisAsTime=False): |
|
164 | 164 | |
|
165 | 165 | matplotlib.pyplot.ioff() |
|
166 | 166 | |
|
167 | 167 | divider = make_axes_locatable(ax) |
|
168 | 168 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
169 | 169 | fig = ax.get_figure() |
|
170 | 170 | fig.add_axes(ax_cb) |
|
171 | 171 | |
|
172 | 172 | ax.set_xlim([xmin,xmax]) |
|
173 | 173 | ax.set_ylim([ymin,ymax]) |
|
174 | 174 | |
|
175 | 175 | printLabels(ax, xlabel, ylabel, title) |
|
176 | 176 | |
|
177 | 177 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
178 | 178 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
179 | 179 | cb.set_label(cblabel) |
|
180 | 180 | |
|
181 | 181 | # for tl in ax_cb.get_yticklabels(): |
|
182 | 182 | # tl.set_visible(True) |
|
183 | 183 | |
|
184 | 184 | for tick in ax.yaxis.get_major_ticks(): |
|
185 | 185 | tick.label.set_fontsize(ticksize) |
|
186 | 186 | |
|
187 | 187 | for tick in ax.xaxis.get_major_ticks(): |
|
188 | 188 | tick.label.set_fontsize(ticksize) |
|
189 | 189 | |
|
190 | 190 | for tick in cb.ax.get_yticklabels(): |
|
191 | 191 | tick.set_fontsize(ticksize) |
|
192 | 192 | |
|
193 | 193 | ax_cb.yaxis.tick_right() |
|
194 | 194 | |
|
195 | 195 | if '0.' in matplotlib.__version__[0:2]: |
|
196 | 196 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
197 | 197 | return imesh |
|
198 | 198 | |
|
199 | 199 | if '1.0.' in matplotlib.__version__[0:4]: |
|
200 | 200 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
201 | 201 | return imesh |
|
202 | 202 | |
|
203 | 203 | matplotlib.pyplot.tight_layout() |
|
204 | 204 | |
|
205 | 205 | if XAxisAsTime: |
|
206 | 206 | |
|
207 | 207 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
208 | 208 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
209 | 209 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
210 | 210 | |
|
211 | 211 | matplotlib.pyplot.ion() |
|
212 | 212 | return imesh |
|
213 | 213 | |
|
214 | 214 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
215 | 215 | |
|
216 | 216 | z = z.T |
|
217 | 217 | |
|
218 | 218 | ax = imesh.get_axes() |
|
219 | 219 | |
|
220 | 220 | printLabels(ax, xlabel, ylabel, title) |
|
221 | 221 | |
|
222 | 222 | imesh.set_array(z.ravel()) |
|
223 | 223 | |
|
224 | 224 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
225 | 225 | |
|
226 | 226 | printLabels(ax, xlabel, ylabel, title) |
|
227 | 227 | |
|
228 | 228 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
229 | 229 | |
|
230 | 230 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
231 | 231 | |
|
232 | 232 | printLabels(ax, xlabel, ylabel, title) |
|
233 | 233 | |
|
234 | 234 | ax.collections.remove(ax.collections[0]) |
|
235 | 235 | |
|
236 | 236 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
237 | 237 | |
|
238 | 238 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
239 | 239 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
240 | 240 | nxticks=4, nyticks=10, |
|
241 | 241 | grid=None): |
|
242 | 242 | |
|
243 | 243 | """ |
|
244 | 244 | |
|
245 | 245 | Input: |
|
246 | 246 | grid : None, 'both', 'x', 'y' |
|
247 | 247 | """ |
|
248 | 248 | |
|
249 | 249 | matplotlib.pyplot.ioff() |
|
250 | 250 | |
|
251 | 251 | lines = ax.plot(x.T, y) |
|
252 | 252 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
253 | 253 | leg.get_frame().set_alpha(0.5) |
|
254 | 254 | ax.set_xlim([xmin,xmax]) |
|
255 | 255 | ax.set_ylim([ymin,ymax]) |
|
256 | 256 | printLabels(ax, xlabel, ylabel, title) |
|
257 | 257 | |
|
258 | 258 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
259 | 259 | ax.set_xticks(xtickspos) |
|
260 | 260 | |
|
261 | 261 | for tick in ax.get_xticklabels(): |
|
262 | 262 | tick.set_visible(xtick_visible) |
|
263 | 263 | |
|
264 | 264 | for tick in ax.xaxis.get_major_ticks(): |
|
265 | 265 | tick.label.set_fontsize(ticksize) |
|
266 | 266 | |
|
267 | 267 | for tick in ax.get_yticklabels(): |
|
268 | 268 | tick.set_visible(ytick_visible) |
|
269 | 269 | |
|
270 | 270 | for tick in ax.yaxis.get_major_ticks(): |
|
271 | 271 | tick.label.set_fontsize(ticksize) |
|
272 | 272 | |
|
273 | 273 | iplot = ax.lines[-1] |
|
274 | 274 | |
|
275 | 275 | if '0.' in matplotlib.__version__[0:2]: |
|
276 | 276 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
277 | 277 | return iplot |
|
278 | 278 | |
|
279 | 279 | if '1.0.' in matplotlib.__version__[0:4]: |
|
280 | 280 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
281 | 281 | return iplot |
|
282 | 282 | |
|
283 | 283 | if grid != None: |
|
284 | 284 | ax.grid(b=True, which='major', axis=grid) |
|
285 | 285 | |
|
286 | 286 | matplotlib.pyplot.tight_layout() |
|
287 | 287 | |
|
288 | 288 | matplotlib.pyplot.ion() |
|
289 | 289 | |
|
290 | 290 | return iplot |
|
291 | 291 | |
|
292 | 292 | |
|
293 | 293 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
294 | 294 | |
|
295 | 295 | ax = iplot.get_axes() |
|
296 | 296 | |
|
297 | 297 | printLabels(ax, xlabel, ylabel, title) |
|
298 | 298 | |
|
299 | 299 | for i in range(len(ax.lines)): |
|
300 | 300 | line = ax.lines[i] |
|
301 | 301 | line.set_data(x[i,:],y) |
|
302 | 302 | |
|
303 | 303 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
304 | 304 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
305 | 305 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
306 | 306 | grid=None, XAxisAsTime=False): |
|
307 | 307 | |
|
308 | 308 | """ |
|
309 | 309 | |
|
310 | 310 | Input: |
|
311 | 311 | grid : None, 'both', 'x', 'y' |
|
312 | 312 | """ |
|
313 | 313 | |
|
314 | 314 | matplotlib.pyplot.ioff() |
|
315 | 315 | |
|
316 | 316 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
317 | 317 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) |
|
318 | 318 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
319 | 319 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
320 | 320 | |
|
321 | 321 | for label in leg.get_texts(): label.set_fontsize(9) |
|
322 | 322 | |
|
323 | 323 | ax.set_xlim([xmin,xmax]) |
|
324 | 324 | ax.set_ylim([ymin,ymax]) |
|
325 | 325 | printLabels(ax, xlabel, ylabel, title) |
|
326 | 326 | |
|
327 | 327 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
328 | 328 | # ax.set_xticks(xtickspos) |
|
329 | 329 | |
|
330 | 330 | for tick in ax.get_xticklabels(): |
|
331 | 331 | tick.set_visible(xtick_visible) |
|
332 | 332 | |
|
333 | 333 | for tick in ax.xaxis.get_major_ticks(): |
|
334 | 334 | tick.label.set_fontsize(ticksize) |
|
335 | 335 | |
|
336 | 336 | for tick in ax.get_yticklabels(): |
|
337 | 337 | tick.set_visible(ytick_visible) |
|
338 | 338 | |
|
339 | 339 | for tick in ax.yaxis.get_major_ticks(): |
|
340 | 340 | tick.label.set_fontsize(ticksize) |
|
341 | 341 | |
|
342 | 342 | iplot = ax.lines[-1] |
|
343 | 343 | |
|
344 | 344 | if '0.' in matplotlib.__version__[0:2]: |
|
345 | 345 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
346 | 346 | return iplot |
|
347 | 347 | |
|
348 | 348 | if '1.0.' in matplotlib.__version__[0:4]: |
|
349 | 349 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
350 | 350 | return iplot |
|
351 | 351 | |
|
352 | 352 | if grid != None: |
|
353 | 353 | ax.grid(b=True, which='major', axis=grid) |
|
354 | 354 | |
|
355 | 355 | matplotlib.pyplot.tight_layout() |
|
356 | 356 | |
|
357 | 357 | if XAxisAsTime: |
|
358 | 358 | |
|
359 | 359 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
360 | 360 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
361 | 361 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
362 | 362 | |
|
363 | 363 | matplotlib.pyplot.ion() |
|
364 | 364 | |
|
365 | 365 | return iplot |
|
366 | 366 | |
|
367 | 367 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
368 | 368 | |
|
369 | 369 | ax = iplot.get_axes() |
|
370 | 370 | |
|
371 | 371 | printLabels(ax, xlabel, ylabel, title) |
|
372 | 372 | |
|
373 | 373 | for i in range(len(ax.lines)): |
|
374 | 374 | line = ax.lines[i] |
|
375 | 375 | line.set_data(x,y[i,:]) |
|
376 | 376 | |
|
377 | 377 | def draw(fig): |
|
378 | 378 | |
|
379 | 379 | if type(fig) == 'int': |
|
380 | 380 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
381 | 381 | |
|
382 | 382 | fig.canvas.draw() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now