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