##// END OF EJS Templates
replace method get_axes() by axes property (deprecation warning)
Juan C. Valdez -
r879:5e656c74cb4d
parent child
Show More
@@ -1,468 +1,468
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 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 12 import matplotlib.pyplot
13 13
14 14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 15 from matplotlib.ticker import FuncFormatter, LinearLocator
16 16
17 17 ###########################################
18 18 #Actualizacion de las funciones del driver
19 19 ###########################################
20 20
21 21 # create jro colormap
22 22
23 23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
24 24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
25 25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
26 26 matplotlib.pyplot.register_cmap(cmap=ncmap)
27 27
28 28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
29 29
30 30 matplotlib.pyplot.ioff()
31 31
32 32 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
33 33 fig.canvas.manager.set_window_title(wintitle)
34 34 # fig.canvas.manager.resize(width, height)
35 35 matplotlib.pyplot.ion()
36 36
37 37 if show:
38 38 matplotlib.pyplot.show()
39 39
40 40 return fig
41 41
42 42 def closeFigure(show=False, fig=None):
43 43
44 44 # matplotlib.pyplot.ioff()
45 45 # matplotlib.pyplot.pause(0)
46 46
47 47 if show:
48 48 matplotlib.pyplot.show()
49 49
50 50 if fig != None:
51 51 matplotlib.pyplot.close(fig)
52 52 # matplotlib.pyplot.pause(0)
53 53 # matplotlib.pyplot.ion()
54 54
55 55 return
56 56
57 57 matplotlib.pyplot.close("all")
58 58 # matplotlib.pyplot.pause(0)
59 59 # matplotlib.pyplot.ion()
60 60
61 61 return
62 62
63 63 def saveFigure(fig, filename):
64 64
65 65 # matplotlib.pyplot.ioff()
66 66 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
67 67 # matplotlib.pyplot.ion()
68 68
69 69 def clearFigure(fig):
70 70
71 71 fig.clf()
72 72
73 73 def setWinTitle(fig, title):
74 74
75 75 fig.canvas.manager.set_window_title(title)
76 76
77 77 def setTitle(fig, title):
78 78
79 79 fig.suptitle(title)
80 80
81 81 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
82 82
83 83 matplotlib.pyplot.ioff()
84 84 matplotlib.pyplot.figure(fig.number)
85 85 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
86 86 (xpos, ypos),
87 87 colspan=colspan,
88 88 rowspan=rowspan,
89 89 polar=polar)
90 90
91 91 matplotlib.pyplot.ion()
92 92 return axes
93 93
94 94 def setAxesText(ax, text):
95 95
96 96 ax.annotate(text,
97 97 xy = (.1, .99),
98 98 xycoords = 'figure fraction',
99 99 horizontalalignment = 'left',
100 100 verticalalignment = 'top',
101 101 fontsize = 10)
102 102
103 103 def printLabels(ax, xlabel, ylabel, title):
104 104
105 105 ax.set_xlabel(xlabel, size=11)
106 106 ax.set_ylabel(ylabel, size=11)
107 107 ax.set_title(title, size=8)
108 108
109 109 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
110 110 ticksize=9, xtick_visible=True, ytick_visible=True,
111 111 nxticks=4, nyticks=10,
112 112 grid=None,color='blue'):
113 113
114 114 """
115 115
116 116 Input:
117 117 grid : None, 'both', 'x', 'y'
118 118 """
119 119
120 120 matplotlib.pyplot.ioff()
121 121
122 122 ax.set_xlim([xmin,xmax])
123 123 ax.set_ylim([ymin,ymax])
124 124
125 125 printLabels(ax, xlabel, ylabel, title)
126 126
127 127 ######################################################
128 128 if (xmax-xmin)<=1:
129 129 xtickspos = numpy.linspace(xmin,xmax,nxticks)
130 130 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
131 131 ax.set_xticks(xtickspos)
132 132 else:
133 133 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
134 134 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
135 135 ax.set_xticks(xtickspos)
136 136
137 137 for tick in ax.get_xticklabels():
138 138 tick.set_visible(xtick_visible)
139 139
140 140 for tick in ax.xaxis.get_major_ticks():
141 141 tick.label.set_fontsize(ticksize)
142 142
143 143 ######################################################
144 144 for tick in ax.get_yticklabels():
145 145 tick.set_visible(ytick_visible)
146 146
147 147 for tick in ax.yaxis.get_major_ticks():
148 148 tick.label.set_fontsize(ticksize)
149 149
150 150 ax.plot(x, y, color=color)
151 151 iplot = ax.lines[-1]
152 152
153 153 ######################################################
154 154 if '0.' in matplotlib.__version__[0:2]:
155 155 print "The matplotlib version has to be updated to 1.1 or newer"
156 156 return iplot
157 157
158 158 if '1.0.' in matplotlib.__version__[0:4]:
159 159 print "The matplotlib version has to be updated to 1.1 or newer"
160 160 return iplot
161 161
162 162 if grid != None:
163 163 ax.grid(b=True, which='major', axis=grid)
164 164
165 165 matplotlib.pyplot.tight_layout()
166 166
167 167 matplotlib.pyplot.ion()
168 168
169 169 return iplot
170 170
171 171 def set_linedata(ax, x, y, idline):
172 172
173 173 ax.lines[idline].set_data(x,y)
174 174
175 175 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
176 176
177 ax = iplot.get_axes()
177 ax = iplot.axes
178 178
179 179 printLabels(ax, xlabel, ylabel, title)
180 180
181 181 set_linedata(ax, x, y, idline=0)
182 182
183 183 def addpline(ax, x, y, color, linestyle, lw):
184 184
185 185 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
186 186
187 187
188 188 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
189 189 xlabel='', ylabel='', title='', ticksize = 9,
190 190 colormap='jet',cblabel='', cbsize="5%",
191 191 XAxisAsTime=False):
192 192
193 193 matplotlib.pyplot.ioff()
194 194
195 195 divider = make_axes_locatable(ax)
196 196 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
197 197 fig = ax.get_figure()
198 198 fig.add_axes(ax_cb)
199 199
200 200 ax.set_xlim([xmin,xmax])
201 201 ax.set_ylim([ymin,ymax])
202 202
203 203 printLabels(ax, xlabel, ylabel, title)
204 204
205 205 z = numpy.ma.masked_invalid(z)
206 206 cmap=matplotlib.pyplot.get_cmap(colormap)
207 207 cmap.set_bad('white', 1.)
208 208 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
209 209 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
210 210 cb.set_label(cblabel)
211 211
212 212 # for tl in ax_cb.get_yticklabels():
213 213 # tl.set_visible(True)
214 214
215 215 for tick in ax.yaxis.get_major_ticks():
216 216 tick.label.set_fontsize(ticksize)
217 217
218 218 for tick in ax.xaxis.get_major_ticks():
219 219 tick.label.set_fontsize(ticksize)
220 220
221 221 for tick in cb.ax.get_yticklabels():
222 222 tick.set_fontsize(ticksize)
223 223
224 224 ax_cb.yaxis.tick_right()
225 225
226 226 if '0.' in matplotlib.__version__[0:2]:
227 227 print "The matplotlib version has to be updated to 1.1 or newer"
228 228 return imesh
229 229
230 230 if '1.0.' in matplotlib.__version__[0:4]:
231 231 print "The matplotlib version has to be updated to 1.1 or newer"
232 232 return imesh
233 233
234 234 matplotlib.pyplot.tight_layout()
235 235
236 236 if XAxisAsTime:
237 237
238 238 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
239 239 ax.xaxis.set_major_formatter(FuncFormatter(func))
240 240 ax.xaxis.set_major_locator(LinearLocator(7))
241 241
242 242 matplotlib.pyplot.ion()
243 243 return imesh
244 244
245 245 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
246 246
247 247 z = z.T
248 ax = imesh.get_axes()
248 ax = imesh.axes
249 249 printLabels(ax, xlabel, ylabel, title)
250 250 imesh.set_array(z.ravel())
251 251
252 252 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
253 253
254 254 printLabels(ax, xlabel, ylabel, title)
255 255
256 256 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
257 257
258 258 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
259 259
260 260 printLabels(ax, xlabel, ylabel, title)
261 261
262 262 ax.collections.remove(ax.collections[0])
263 263
264 264 z = numpy.ma.masked_invalid(z)
265 265
266 266 cmap=matplotlib.pyplot.get_cmap(colormap)
267 267 cmap.set_bad('white', 1.)
268 268
269 269
270 270 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
271 271
272 272 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
273 273 ticksize=9, xtick_visible=True, ytick_visible=True,
274 274 nxticks=4, nyticks=10,
275 275 grid=None):
276 276
277 277 """
278 278
279 279 Input:
280 280 grid : None, 'both', 'x', 'y'
281 281 """
282 282
283 283 matplotlib.pyplot.ioff()
284 284
285 285 lines = ax.plot(x.T, y)
286 286 leg = ax.legend(lines, legendlabels, loc='upper right')
287 287 leg.get_frame().set_alpha(0.5)
288 288 ax.set_xlim([xmin,xmax])
289 289 ax.set_ylim([ymin,ymax])
290 290 printLabels(ax, xlabel, ylabel, title)
291 291
292 292 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
293 293 ax.set_xticks(xtickspos)
294 294
295 295 for tick in ax.get_xticklabels():
296 296 tick.set_visible(xtick_visible)
297 297
298 298 for tick in ax.xaxis.get_major_ticks():
299 299 tick.label.set_fontsize(ticksize)
300 300
301 301 for tick in ax.get_yticklabels():
302 302 tick.set_visible(ytick_visible)
303 303
304 304 for tick in ax.yaxis.get_major_ticks():
305 305 tick.label.set_fontsize(ticksize)
306 306
307 307 iplot = ax.lines[-1]
308 308
309 309 if '0.' in matplotlib.__version__[0:2]:
310 310 print "The matplotlib version has to be updated to 1.1 or newer"
311 311 return iplot
312 312
313 313 if '1.0.' in matplotlib.__version__[0:4]:
314 314 print "The matplotlib version has to be updated to 1.1 or newer"
315 315 return iplot
316 316
317 317 if grid != None:
318 318 ax.grid(b=True, which='major', axis=grid)
319 319
320 320 matplotlib.pyplot.tight_layout()
321 321
322 322 matplotlib.pyplot.ion()
323 323
324 324 return iplot
325 325
326 326
327 327 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
328 328
329 ax = iplot.get_axes()
329 ax = iplot.axes
330 330
331 331 printLabels(ax, xlabel, ylabel, title)
332 332
333 333 for i in range(len(ax.lines)):
334 334 line = ax.lines[i]
335 335 line.set_data(x[i,:],y)
336 336
337 337 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
338 338 ticksize=9, xtick_visible=True, ytick_visible=True,
339 339 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
340 340 grid=None, XAxisAsTime=False):
341 341
342 342 """
343 343
344 344 Input:
345 345 grid : None, 'both', 'x', 'y'
346 346 """
347 347
348 348 matplotlib.pyplot.ioff()
349 349
350 350 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
351 351 lines = ax.plot(x, y.T)
352 352 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
353 353 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
354 354
355 355 leg = ax.legend(lines, legendlabels,
356 356 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
357 357
358 358 for label in leg.get_texts(): label.set_fontsize(9)
359 359
360 360 ax.set_xlim([xmin,xmax])
361 361 ax.set_ylim([ymin,ymax])
362 362 printLabels(ax, xlabel, ylabel, title)
363 363
364 364 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
365 365 # ax.set_xticks(xtickspos)
366 366
367 367 for tick in ax.get_xticklabels():
368 368 tick.set_visible(xtick_visible)
369 369
370 370 for tick in ax.xaxis.get_major_ticks():
371 371 tick.label.set_fontsize(ticksize)
372 372
373 373 for tick in ax.get_yticklabels():
374 374 tick.set_visible(ytick_visible)
375 375
376 376 for tick in ax.yaxis.get_major_ticks():
377 377 tick.label.set_fontsize(ticksize)
378 378
379 379 iplot = ax.lines[-1]
380 380
381 381 if '0.' in matplotlib.__version__[0:2]:
382 382 print "The matplotlib version has to be updated to 1.1 or newer"
383 383 return iplot
384 384
385 385 if '1.0.' in matplotlib.__version__[0:4]:
386 386 print "The matplotlib version has to be updated to 1.1 or newer"
387 387 return iplot
388 388
389 389 if grid != None:
390 390 ax.grid(b=True, which='major', axis=grid)
391 391
392 392 matplotlib.pyplot.tight_layout()
393 393
394 394 if XAxisAsTime:
395 395
396 396 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
397 397 ax.xaxis.set_major_formatter(FuncFormatter(func))
398 398 ax.xaxis.set_major_locator(LinearLocator(7))
399 399
400 400 matplotlib.pyplot.ion()
401 401
402 402 return iplot
403 403
404 404 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
405 405
406 ax = iplot.get_axes()
406 ax = iplot.axes
407 407
408 408 printLabels(ax, xlabel, ylabel, title)
409 409
410 410 for i in range(len(ax.lines)):
411 411 line = ax.lines[i]
412 412 line.set_data(x,y[i,:])
413 413
414 414 def createPolar(ax, x, y,
415 415 xlabel='', ylabel='', title='', ticksize = 9,
416 416 colormap='jet',cblabel='', cbsize="5%",
417 417 XAxisAsTime=False):
418 418
419 419 matplotlib.pyplot.ioff()
420 420
421 421 ax.plot(x,y,'bo', markersize=5)
422 422 # ax.set_rmax(90)
423 423 ax.set_ylim(0,90)
424 424 ax.set_yticks(numpy.arange(0,90,20))
425 425 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
426 426 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
427 427 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
428 ax.yaxis.labelpad = 250
428 ax.yaxis.labelpad = 40
429 429 printLabels(ax, xlabel, ylabel, title)
430 430 iplot = ax.lines[-1]
431 431
432 432 if '0.' in matplotlib.__version__[0:2]:
433 433 print "The matplotlib version has to be updated to 1.1 or newer"
434 434 return iplot
435 435
436 436 if '1.0.' in matplotlib.__version__[0:4]:
437 437 print "The matplotlib version has to be updated to 1.1 or newer"
438 438 return iplot
439 439
440 440 # if grid != None:
441 441 # ax.grid(b=True, which='major', axis=grid)
442 442
443 443 matplotlib.pyplot.tight_layout()
444 444
445 445 matplotlib.pyplot.ion()
446 446
447 447
448 448 return iplot
449 449
450 450 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
451 451
452 ax = iplot.get_axes()
452 ax = iplot.axes
453 453
454 454 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
455 455 printLabels(ax, xlabel, ylabel, title)
456 456
457 457 set_linedata(ax, x, y, idline=0)
458 458
459 459 def draw(fig):
460 460
461 461 if type(fig) == 'int':
462 462 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
463 463
464 464 fig.canvas.draw()
465 465
466 466 def pause(interval=0.000001):
467 467
468 468 matplotlib.pyplot.pause(interval)
General Comments 0
You need to be logged in to leave comments. Login now