##// END OF EJS Templates
Regresa a la version original desarrollada por Marco M.
Alexander Valdez -
r165:6be50d6279e1
parent child
Show More
@@ -1,1211 +1,1211
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @autor $Author: dsuarez $
5 5 @version $Id: BaseGraph.py 117 2012-09-04 21:16:59Z dsuarez $
6 6
7 7 '''
8 8 #from __future__ import division
9 9 #import os
10 10 import numpy
11 11 #import sys
12 12 import time
13 13 import datetime
14 14
15 15 #import plplot
16 16 import matplotlib as mpl
17 #mpl.use('TKAgg')
17 mpl.use('TKAgg')
18 18 import matplotlib.pyplot as plt
19 19
20 #import scitools.numpyutils as sn
20 import scitools.numpyutils as sn
21 21
22 22 def cmap1_init(colormap='gray'):
23 23
24 24 # if colormap == None:
25 25 # return
26 26 #
27 27 # ncolor = None
28 28 # rgb_lvl = None
29 29 #
30 30 # # Routine for defining a specific color map 1 in HLS space.
31 31 # # if gray is true, use basic grayscale variation from half-dark to light.
32 32 # # otherwise use false color variation from blue (240 deg) to red (360 deg).
33 33 #
34 34 # # Independent variable of control points.
35 35 # i = numpy.array((0., 1.))
36 36 # if colormap=='gray':
37 37 # ncolor = 256
38 38 # # Hue for control points. Doesn't matter since saturation is zero.
39 39 # h = numpy.array((0., 0.))
40 40 # # Lightness ranging from half-dark (for interest) to light.
41 41 # l = numpy.array((0.5, 1.))
42 42 # # Gray scale has zero saturation
43 43 # s = numpy.array((0., 0.))
44 44 #
45 45 # # number of cmap1 colours is 256 in this case.
46 46 # plplot.plscmap1n(ncolor)
47 47 # # Interpolate between control points to set up cmap1.
48 48 # plplot.plscmap1l(0, i, h, l, s)
49 49 #
50 50 # return None
51 51 #
52 52 # if colormap == 'jet':
53 53 # ncolor = 256
54 54 # pos = numpy.zeros((ncolor))
55 55 # r = numpy.zeros((ncolor))
56 56 # g = numpy.zeros((ncolor))
57 57 # b = numpy.zeros((ncolor))
58 58 #
59 59 # for i in range(ncolor):
60 60 # if(i <= 35.0/100*(ncolor-1)): rf = 0.0
61 61 # elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
62 62 # elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
63 63 # else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
64 64 #
65 65 # if(i <= 12.0/100*(ncolor-1)): gf = 0.0
66 66 # elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
67 67 # elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
68 68 # elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
69 69 # else: gf = 0.0
70 70 #
71 71 # if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
72 72 # elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
73 73 # elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
74 74 # else: bf = 0
75 75 #
76 76 # r[i] = rf
77 77 # g[i] = gf
78 78 # b[i] = bf
79 79 #
80 80 # pos[i] = float(i)/float(ncolor-1)
81 81 #
82 82 #
83 83 # plplot.plscmap1n(ncolor)
84 84 # plplot.plscmap1l(1, pos, r, g, b)
85 85 #
86 86 #
87 87 #
88 88 # if colormap=='br_green':
89 89 # ncolor = 256
90 90 # # Hue ranges from blue (240 deg) to red (0 or 360 deg)
91 91 # h = numpy.array((240., 0.))
92 92 # # Lightness and saturation are constant (values taken from C example).
93 93 # l = numpy.array((0.6, 0.6))
94 94 # s = numpy.array((0.8, 0.8))
95 95 #
96 96 # # number of cmap1 colours is 256 in this case.
97 97 # plplot.plscmap1n(ncolor)
98 98 # # Interpolate between control points to set up cmap1.
99 99 # plplot.plscmap1l(0, i, h, l, s)
100 100 #
101 101 # return None
102 102 #
103 103 # if colormap=='tricolor':
104 104 # ncolor = 3
105 105 # # Hue ranges from blue (240 deg) to red (0 or 360 deg)
106 106 # h = numpy.array((240., 0.))
107 107 # # Lightness and saturation are constant (values taken from C example).
108 108 # l = numpy.array((0.6, 0.6))
109 109 # s = numpy.array((0.8, 0.8))
110 110 #
111 111 # # number of cmap1 colours is 256 in this case.
112 112 # plplot.plscmap1n(ncolor)
113 113 # # Interpolate between control points to set up cmap1.
114 114 # plplot.plscmap1l(0, i, h, l, s)
115 115 #
116 116 # return None
117 117 #
118 118 # if colormap == 'rgb' or colormap == 'rgb666':
119 119 #
120 120 # color_sz = 6
121 121 # ncolor = color_sz*color_sz*color_sz
122 122 # pos = numpy.zeros((ncolor))
123 123 # r = numpy.zeros((ncolor))
124 124 # g = numpy.zeros((ncolor))
125 125 # b = numpy.zeros((ncolor))
126 126 # ind = 0
127 127 # for ri in range(color_sz):
128 128 # for gi in range(color_sz):
129 129 # for bi in range(color_sz):
130 130 # r[ind] = ri/(color_sz-1.0)
131 131 # g[ind] = gi/(color_sz-1.0)
132 132 # b[ind] = bi/(color_sz-1.0)
133 133 # pos[ind] = ind/(ncolor-1.0)
134 134 # ind += 1
135 135 # rgb_lvl = [6,6,6] #Levels for RGB colors
136 136 #
137 137 # if colormap == 'rgb676':
138 138 # ncolor = 6*7*6
139 139 # pos = numpy.zeros((ncolor))
140 140 # r = numpy.zeros((ncolor))
141 141 # g = numpy.zeros((ncolor))
142 142 # b = numpy.zeros((ncolor))
143 143 # ind = 0
144 144 # for ri in range(8):
145 145 # for gi in range(8):
146 146 # for bi in range(4):
147 147 # r[ind] = ri/(6-1.0)
148 148 # g[ind] = gi/(7-1.0)
149 149 # b[ind] = bi/(6-1.0)
150 150 # pos[ind] = ind/(ncolor-1.0)
151 151 # ind += 1
152 152 # rgb_lvl = [6,7,6] #Levels for RGB colors
153 153 #
154 154 # if colormap == 'rgb685':
155 155 # ncolor = 6*8*5
156 156 # pos = numpy.zeros((ncolor))
157 157 # r = numpy.zeros((ncolor))
158 158 # g = numpy.zeros((ncolor))
159 159 # b = numpy.zeros((ncolor))
160 160 # ind = 0
161 161 # for ri in range(8):
162 162 # for gi in range(8):
163 163 # for bi in range(4):
164 164 # r[ind] = ri/(6-1.0)
165 165 # g[ind] = gi/(8-1.0)
166 166 # b[ind] = bi/(5-1.0)
167 167 # pos[ind] = ind/(ncolor-1.0)
168 168 # ind += 1
169 169 # rgb_lvl = [6,8,5] #Levels for RGB colors
170 170 #
171 171 # if colormap == 'rgb884':
172 172 # ncolor = 8*8*4
173 173 # pos = numpy.zeros((ncolor))
174 174 # r = numpy.zeros((ncolor))
175 175 # g = numpy.zeros((ncolor))
176 176 # b = numpy.zeros((ncolor))
177 177 # ind = 0
178 178 # for ri in range(8):
179 179 # for gi in range(8):
180 180 # for bi in range(4):
181 181 # r[ind] = ri/(8-1.0)
182 182 # g[ind] = gi/(8-1.0)
183 183 # b[ind] = bi/(4-1.0)
184 184 # pos[ind] = ind/(ncolor-1.0)
185 185 # ind += 1
186 186 # rgb_lvl = [8,8,4] #Levels for RGB colors
187 187 #
188 188 # if ncolor == None:
189 189 # raise ValueError, 'The colormap selected is not valid'
190 190 #
191 191 # plplot.plscmap1n(ncolor)
192 192 # plplot.plscmap1l(1, pos, r, g, b)
193 193 #
194 194 # return rgb_lvl
195 195 pass
196 196
197 197 def setColormap(colormap='jet'):
198 198 # cmap1_init(colormap)
199 199 pass
200 200
201 201 def savePlplot(filename,width,height):
202 202 # curr_strm = plplot.plgstrm()
203 203 # save_strm = plplot.plmkstrm()
204 204 # plplot.plsetopt('geometry', '%dx%d'%(width,height))
205 205 # plplot.plsdev('png')
206 206 # plplot.plsfnam(filename)
207 207 # plplot.plcpstrm(curr_strm,0)
208 208 # plplot.plreplot()
209 209 # plplot.plend1()
210 210 # plplot.plsstrm(curr_strm)
211 211 pass
212 212
213 213 def initMatplotlib(indexFig,ncol,nrow,winTitle,width,height):
214 214
215 215 plt.ioff()
216 216 fig = plt.figure(indexFig)
217 217 fig.canvas.manager.set_window_title(winTitle)
218 218 fig.canvas.manager.resize(width,height)
219 219 # fig.add_subplot(nrow,ncol,1)
220 220 plt.ion()
221 221
222 222 def setNewPage():
223 223 # plplot.plbop()
224 224 # plplot.pladv(0)
225 225 plt.clf()
226 226
227 227 def closePage():
228 228 # plplot.pleop()
229 229 pass
230 230
231 231 def clearData(objGraph):
232 232 objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], 'bc', 'bc')
233 233
234 234 objGraph.setColor(15) #Setting Line Color to White
235 235
236 236 if objGraph.datatype == 'complex':
237 237 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real)
238 238 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag)
239 239
240 240 if objGraph.datatype == 'real':
241 241 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata)
242 242
243 243 objGraph.setColor(1) #Setting Line Color to Black
244 244 # objGraph.setLineStyle(2)
245 245 # objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], 'bcntg', 'bc')
246 246 # objGraph.setLineStyle(1)
247 247
248 248 def setFigure(indexFig):
249 249 # plplot.plsstrm(indexFig)
250 250 plt.figure(indexFig)
251 251
252 252 def refresh():
253 253 # plplot.refresh()
254 254 plt.draw()
255 255
256 256 def show():
257 257 # plplot.plspause(True)
258 258 # plplot.plend()
259 259 plt.ioff()
260 260 plt.show()
261 261 plt.ion()
262 262
263 263 def setPlTitle(pltitle,color, szchar=0.7):
264 264 # setSubpages(1, 0)
265 265 # plplot.pladv(0)
266 266 # plplot.plvpor(0., 1., 0., 1.)
267 267 #
268 268 # if color == 'black':
269 269 # plplot.plcol0(1)
270 270 # if color == 'white':
271 271 # plplot.plcol0(15)
272 272 #
273 273 # plplot.plschr(0.0,szchar)
274 274 # plplot.plmtex('t',-1., 0.5, 0.5, pltitle)
275 275 pass
276 276
277 277 def setSubpages(ncol,nrow):
278 278 # plplot.plssub(ncol,nrow)
279 279 pass
280 280
281 281 class BaseGraph:
282 282
283 283 __name = None
284 284 __xpos = None
285 285 __ypos = None
286 286 __subplot = None
287 287 __xg = None
288 288 __yg = None
289 289 __axesId = None
290 290 xdata = None
291 291 ydata = None
292 292 getGrid = True
293 293 xaxisIsTime = False
294 294 deltax = None
295 295 xmin = None
296 296 xmax = None
297 297
298 298 def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0):
299 299
300 300 self.setName(name)
301 301 self.setScreenPos(xpos, ypos)
302 302 self.setSubPlot(subplot)
303 303 self.setXYZrange(xrange,yrange,zrange)
304 304 self.setSizeOfChar(szchar)
305 305 self.setLabels(xlabel,ylabel,title)
306 306 self.getGrid = True
307 307 self.xaxisIsTime = False
308 308 self.deltax = deltax
309 309 pass
310 310
311 311 def makeAxes(self,indexFig,nrow,ncol,subplot):
312 312 fig = plt.figure(indexFig)
313 313 self.__axesId = fig.add_subplot(nrow,ncol,subplot)
314 314
315 315 def setParentAxesId(self,parent):
316 316 self.__axesId = parent.__axesId
317 317
318 318 def setName(self, name):
319 319 self.__name = name
320 320
321 321 def setScreenPos(self,xpos,ypos):
322 322 self.__xpos = xpos
323 323 self.__ypos = ypos
324 324
325 325 def setSubPlot(self,subplot):
326 326 self.__subplot = subplot
327 327
328 328 def setXYZrange(self,xrange,yrange,zrange):
329 329 self.xrange = xrange
330 330 self.yrange = yrange
331 331 self.zrange = zrange
332 332
333 333 def setSizeOfChar(self,szchar):
334 334 self.__szchar = szchar
335 335
336 336 def setLabels(self,xlabel=None,ylabel=None,title=None):
337 337 if xlabel != None: self.xlabel = xlabel
338 338 if ylabel != None: self.ylabel = ylabel
339 339 if title != None: self.title = title
340 340
341 341 def setXYData(self,xdata=None,ydata=None,datatype='real'):
342 342 if ((xdata != None) and (ydata != None)):
343 343 self.xdata = xdata
344 344 self.ydata = ydata
345 345 self.datatype = datatype
346 346 if ((self.xdata == None) and (self.ydata == None)):
347 347 return None
348 348 return 1
349 349
350 350 def setLineStyle(self, style):
351 351 # plplot.pllsty(style)
352 352 pass
353 353
354 354 def setColor(self, color):
355 355 # plplot.plcol0(color)
356 356 pass
357 357
358 358 def setXAxisAsTime(self, value=False):
359 359 self.xaxisIsTime = value
360 360
361 361 def basicLineTimePlot(self, x, y, colline=1):
362 362 # plplot.plcol0(colline)
363 363 # plplot.plline(x, y)
364 364 # plplot.plcol0(1)
365 365 ax = self.__axesId
366 366 if self.setXYData() == None:
367 367 ax.plot(x,y)
368 368 else:
369 369 ax.lines[0].set_data(x,y)
370 370
371 371 def basicXYPlot(self, x, y):
372 372 # plplot.plline(x, y)
373 373 ax = self.__axesId
374 374 if self.setXYData() == None:
375 375 ax.plot(x,y)
376 376 else:
377 377 ax.lines[0].set_data(x,y)
378 378
379 379 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
380 380 #
381 381 # if xmin == None: xmin = x[0]
382 382 # if xmax == None: xmax = x[-1]
383 383 # if ymin == None: ymin = y[0]
384 384 # if ymax == None: ymax = y[-1]
385 385 # if zmin == None: zmin = numpy.nanmin(data)
386 386 # if zmax == None: zmax = numpy.nanmax(data)
387 387 #
388 388 # plplot.plimage(data,
389 389 # float(x[0]),
390 390 # float(x[-1]),
391 391 # float(y[0]),
392 392 # float(y[-1]),
393 393 # float(zmin),
394 394 # float(zmax),
395 395 # float(xmin),
396 396 # float(xmax),
397 397 # float(ymin),
398 398 # float(ymax)
399 399 # )
400 400 pass
401 401
402 402 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
403 403
404 404 # if not(len(x)>0 and len(y)>0):
405 405 # raise ValueError, 'x axis and y axis are empty'
406 406 #
407 407 # if deltax == None: deltax = x[-1] - x[-2]
408 408 # if deltay == None: deltay = y[-1] - y[-2]
409 409 #
410 410 # x1 = numpy.append(x, x[-1] + deltax)
411 411 # y1 = numpy.append(y, y[-1] + deltay)
412 412 #
413 413 # xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
414 414 # yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
415 415 #
416 416 # self.__xg = xg
417 417 # self.__yg = yg
418 418 #
419 419 # return xg, yg
420 420 pass
421 421
422 422 def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
423 423 # if getGrid:
424 424 # xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
425 425 # else:
426 426 # xg = self.__xg
427 427 # yg = self.__yg
428 428 #
429 429 # plplot.plimagefr(data,
430 430 # float(xmin),
431 431 # float(xmax),
432 432 # float(ymin),
433 433 # float(ymax),
434 434 # 0.,
435 435 # 0.,
436 436 # float(zmin),
437 437 # float(zmax),
438 438 # plplot.pltr2,
439 439 # xg,
440 440 # yg)
441 441
442 442 ax = self.__axesId
443 443 # if self.setXYData() == None:
444 444 ax.pcolormesh(x,y,data.T,vmin=zmin,vmax=zmax)
445 445 # else:
446 446 # ax.lines[0].set_data(x,y)
447 447
448 448
449 449 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
450 450 # data = numpy.arange(256)
451 451 # data = numpy.reshape(data, (1,-1))
452 452 # plplot.plimage(data,
453 453 # float(xmin),
454 454 # float(xmax),
455 455 # float(ymin),
456 456 # float(ymax),
457 457 # 0.,
458 458 # 255.,
459 459 # float(xmin),
460 460 # float(xmax),
461 461 # float(ymin),
462 462 # float(ymax))
463 463 ax = self.__axesId
464 464 cax, kw = mpl.colorbar.make_axes(ax)
465 465 norm = mpl.colors.Normalize(vmin=ymin, vmax=ymax)
466 466 cb = mpl.colorbar.ColorbarBase(cax,norm=norm,**kw)
467 467 self.__colorbarId = cb
468 468 cb.set_label(self.title)
469 469
470 470 def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False):
471 471
472 472 # plplot.plschr(0.0,self.__szchar-0.05)
473 473 # plplot.pladv(self.__subplot)
474 474 # plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
475 475 # plplot.plwind(float(xmin), # self.xrange[0]
476 476 # float(xmax), # self.xrange[1]
477 477 # float(ymin), # self.yrange[0]
478 478 # float(ymax) # self.yrange[1]
479 479 # )
480 480 #
481 481 #
482 482 #
483 483 # if self.xaxisIsTime:
484 484 # plplot.pltimefmt('%H:%M')
485 485 # timedelta = (xmax - xmin + 1)/8.
486 486 # plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
487 487 # else:
488 488 # plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
489 489 #
490 490 #
491 491 # if not(nolabels):
492 492 # plplot.pllab(self.xlabel, self.ylabel, self.title)
493 493
494 494 ax = self.__axesId
495 495 ax.set_xlim([xmin,xmax])
496 496 ax.set_ylim([ymin,ymax])
497 497
498 498 if not(nolabels):
499 499 ax.set_xlabel(self.xlabel)
500 500 ax.set_ylabel(self.ylabel)
501 501 ax.set_title(self.title)
502 502
503 503 # fig = plt.gcf()
504 504 # nrows = self.
505 505 # fig.add_subplot
506 506 # print
507 507 pass
508 508
509 509 def delLabels(self):
510 510 # self.setColor(15) #Setting Line Color to White
511 511 # plplot.pllab(self.xlabel, self.ylabel, self.title)
512 512 # self.setColor(1) #Setting Line Color to Black
513 513 pass
514 514
515 515 def plotImage(self,x,y,z,xrange,yrange,zrange):
516 516 # xi = x[0]
517 517 # xf = x[-1]
518 518 # yi = y[0]
519 519 # yf = y[-1]
520 520 #
521 521 # plplot.plimage(z,
522 522 # float(xi),
523 523 # float(xf),
524 524 # float(yi),
525 525 # float(yf),
526 526 # float(zrange[0]),
527 527 # float(zrange[1]),
528 528 # float(xi),
529 529 # float(xf),
530 530 # float(yrange[0]),
531 531 # yrange[1])
532 532 pass
533 533
534 534 class LinearPlot:
535 535
536 536 linearObjDic = {}
537 537 __xpos = None
538 538 __ypos = None
539 539
540 540 def __init__(self,indexFig,nsubplot,winTitle):
541 541 self.width = 700
542 542 self.height = 150
543 543 self.indexFig = indexFig
544 544 self.ncol = 1
545 545 self.nrow = nsubplot
546 546 initMatplotlib(indexFig,self.ncol,self.nrow,winTitle,self.width,self.height)
547 547
548 548 def setFigure(self,indexFig):
549 549 setFigure(indexFig)
550 550
551 551 def setPosition(self):
552 552
553 553 xi = 0.07; xf = 0.9 #0.8,0.7,0.5
554 554 yi = 0.15; yf = 0.8
555 555
556 556 xpos = [xi,xf]
557 557 ypos = [yi,yf]
558 558
559 559 self.__xpos = xpos
560 560 self.__ypos = ypos
561 561
562 562 return xpos,ypos
563 563
564 564 def show(self):
565 565 show()
566 566
567 567 def refresh(self):
568 568 refresh()
569 569
570 570 def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel):
571 571 szchar = 1.10
572 572 name = 'linear'
573 573 key = name + '%d'%subplot
574 574 xrange = [xmin,xmax]
575 575 yrange = [ymin,ymax]
576 576
577 577 xpos,ypos = self.setPosition()
578 578 linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange)
579 579 linearObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
580 580 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcnst', 'bcnstv')
581 581 self.linearObjDic[key] = linearObj
582 582
583 583
584 584 def plot(self,subplot,x,y,type='abs'):
585 585 name = 'linear'
586 586 key = name + '%d'%subplot
587 587
588 588 linearObj = self.linearObjDic[key]
589 589 #linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcst', 'bcst')
590 590
591 591 # if linearObj.setXYData() != None:
592 592 # clearData(linearObj)
593 593 # else:
594 594 # if type.lower() == 'simple':
595 595 # linearObj.setXYData(x,y,'real')
596 596 # if type.lower() == 'power':
597 597 # linearObj.setXYData(x,abs(y),'real')
598 598 # if type.lower() == 'iq':
599 599 # linearObj.setXYData(x,y,'complex')
600 600
601 601 if type.lower() == 'simple':
602 602 colline = 9
603 603 linearObj.basicLineTimePlot(x, y)
604 604 linearObj.setXYData(x,y,'real')
605 605
606 606 if type.lower() == 'abs':
607 607 colline = 9
608 608 linearObj.basicLineTimePlot(x, abs(y), colline)
609 609 linearObj.setXYData(x,abs(y),'real')
610 610
611 611 if type.lower() == 'iq':
612 612 colline = 9
613 613 linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline)
614 614 colline = 13
615 615 linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline)
616 616 linearObj.setXYData(x,y,'complex')
617 617
618 618 # linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], 'bcst', 'bcst')
619 619
620 620 pass
621 621
622 622
623 623 class PcolorPlot:
624 624
625 625 pcolorObjDic = {}
626 626 colorbarObjDic = {}
627 627 pwprofileObjDic = {}
628 628 showColorbar = None
629 629 showPowerProfile = None
630 630 XAxisAsTime = None
631 631 width = None
632 632 height = None
633 633 __spcxpos = None
634 634 __spcypos = None
635 635 __cmapxpos = None
636 636 __cmapypos = None
637 637 __profxpos = None
638 638 __profypos = None
639 639 __lastTitle = None
640 640
641 641 def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
642 642
643 643 self.width = 460
644 644 self.height = 300
645 645 self.showColorbar = showColorbar
646 646 self.showPowerProfile = showPowerProfile
647 647 self.XAxisAsTime = XAxisAsTime
648 648
649 649 ncol = int(numpy.sqrt(nsubplot)+0.9)
650 650 nrow = int(nsubplot*1./ncol + 0.9)
651 651
652 652 self.ncol = ncol
653 653 self.nrow = nrow
654 654 self.indexFig = indexFig
655 655
656 656 initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height)
657 657 setColormap(colormap)
658 658
659 659 def setFigure(self,indexFig):
660 660 setFigure(indexFig)
661 661
662 662 def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile
663 663 if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075
664 664 else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5
665 665 yi = 0.15; yf = 0.80
666 666
667 667 xpos = [xi,xf]
668 668 ypos = [yi,yf]
669 669
670 670 self.__spcxpos = xpos
671 671 self.__spcypos = ypos
672 672
673 673 return xpos,ypos
674 674
675 675 def setColorbarScreenPos(self):
676 676
677 677 xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03
678 678 yi = self.__spcypos[0]; yf = self.__spcypos[1]
679 679
680 680 xpos = [xi,xf]
681 681 ypos = [yi,yf]
682 682
683 683 self.__cmapxpos = xpos
684 684 self.__cmapypos = ypos
685 685
686 686 return xpos,ypos
687 687
688 688 def setPowerprofileScreenPos(self):
689 689
690 690 xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25
691 691 yi = self.__spcypos[0]; yf = self.__spcypos[1]
692 692
693 693 xpos = [xi,xf]
694 694 ypos = [yi,yf]
695 695
696 696 self.__profxpos = [xi,xf]
697 697 self.__profypos = [yi,yf]
698 698
699 699 return xpos,ypos
700 700
701 701 def createObjects(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel):
702 702
703 703 '''
704 704 Crea los objetos necesarios para un subplot
705 705 '''
706 706
707 707 # Config Spectra plot
708 708
709 709 szchar = 0.7
710 710 name = 'spc'
711 711 key = name + '%d'%subplot
712 712 xrange = [xmin,xmax]
713 713 yrange = [ymin,ymax]
714 714 zrange = [zmin,zmax]
715 715
716 716 xpos,ypos = self.setSpectraPos()
717 717 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange)
718 718 #pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
719 719 self.pcolorObjDic[key] = pcolorObj
720 720
721 721 # Config Colorbar
722 722 if self.showColorbar:
723 723 szchar = 0.65
724 724 name = 'colorbar'
725 725 key = name + '%d'%subplot
726 726
727 727 xpos,ypos = self.setColorbarScreenPos()
728 728 xrange = [0.,1.]
729 729 yrange = [zmin,zmax]
730 730 cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange)
731 731 self.colorbarObjDic[key] = cmapObj
732 732
733 733 # Config Power profile
734 734 if self.showPowerProfile:
735 735 szchar = 0.55
736 736 name = 'pwprofile'
737 737 key = name + '%d'%subplot
738 738
739 739 xpos,ypos = self.setPowerprofileScreenPos()
740 740 xrange = [zmin,zmax]
741 741 yrange = [ymin,ymax]
742 742 powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange)
743 743 #powObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
744 744 self.pwprofileObjDic[key] = powObj
745 745
746 746 def setNewPage(self, pltitle='No title'):
747 747 szchar = 0.7
748 748 setNewPage()
749 749 setPlTitle(pltitle,'black', szchar=szchar)
750 750 setSubpages(self.ncol, self.nrow)
751 751
752 752 def closePage(self):
753 753 closePage()
754 754
755 755 def show(self):
756 756 show()
757 757
758 758 def iniPlot(self,subplot):
759 759 '''
760 760 Inicializa los subplots con su frame, titulo, etc
761 761 '''
762 762
763 763 # Config Spectra plot
764 764 name = 'spc'
765 765 key = name + '%d'%subplot
766 766
767 767 pcolorObj = self.pcolorObjDic[key]
768 768 pcolorObj.makeAxes(self.indexFig,self.nrow,self.ncol,subplot)
769 769 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcnst', 'bcnstv')
770 770
771 771 # Config Colorbar
772 772 if self.showColorbar:
773 773 name = 'colorbar'
774 774 key = name + '%d'%subplot
775 775
776 776 cmapObj = self.colorbarObjDic[key]
777 777 cmapObj.setParentAxesId(pcolorObj)
778 778 # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
779 779 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
780 780 # cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
781 781
782 782 # Config Power profile
783 783 if self.showPowerProfile:
784 784 name = 'pwprofile'
785 785 key = name + '%d'%subplot
786 786
787 787 powObj = self.pwprofileObjDic[key]
788 788 powObj.setLineStyle(2)
789 789 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
790 790 powObj.setLineStyle(1)
791 791 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
792 792
793 793 def printTitle(self,pltitle):
794 794 # if self.__lastTitle != None:
795 795 # setPlTitle(self.__lastTitle,'white')
796 796 #
797 797 # self.__lastTitle = pltitle
798 798
799 799 setPlTitle(pltitle,'black')
800 800
801 801 # setSubpages(self.ncol,self.nrow)
802 802
803 803 def plot(self,subplot,x,y,z,subtitle=''):
804 804 # Spectra plot
805 805
806 806 name = 'spc'
807 807 key = name + '%d'%subplot
808 808
809 809 # newx = [x[0],x[-1]]
810 810 pcolorObj = self.pcolorObjDic[key]
811 811 # pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst')
812 812
813 813 #pcolorObj.delLabels()
814 814 pcolorObj.setLabels(title=subtitle)
815 815
816 816 deltax = None; deltay = None
817 817
818 818 pcolorObj.advPcolorPlot(z,
819 819 x,
820 820 y,
821 821 xmin=pcolorObj.xrange[0],
822 822 xmax=pcolorObj.xrange[1],
823 823 ymin=pcolorObj.yrange[0],
824 824 ymax=pcolorObj.yrange[1],
825 825 zmin=pcolorObj.zrange[0],
826 826 zmax=pcolorObj.zrange[1],
827 827 deltax=deltax,
828 828 deltay=deltay,
829 829 getGrid=pcolorObj.getGrid)
830 830
831 831 #Solo se calcula la primera vez que se ingresa a la funcion
832 832 pcolorObj.getGrid = False
833 833
834 834 #pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], 'bcst', 'bcst', nolabels=True)
835 835
836 836 # Power Profile
837 837 if self.showPowerProfile:
838 838 power = numpy.average(z, axis=0)
839 839 name = 'pwprofile'
840 840 key = name + '%d'%subplot
841 841 powObj = self.pwprofileObjDic[key]
842 842
843 843 if powObj.setXYData() != None:
844 844 #clearData(powObj)
845 845 powObj.setLineStyle(2)
846 846 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
847 847 powObj.setLineStyle(1)
848 848 else:
849 849 powObj.setXYData(power,y)
850 850
851 851 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
852 852 powObj.basicXYPlot(power,y)
853 853 powObj.setXYData(power,y)
854 854
855 855 def savePlot(self,indexFig,filename):
856 856
857 857 width = self.width*self.ncol
858 858 hei = self.height*self.nrow
859 859 savePlplot(filename,width,hei)
860 860
861 861 def refresh(self):
862 862 refresh()
863 863
864 864
865 865 class RtiPlot:
866 866
867 867 pcolorObjDic = {}
868 868 colorbarObjDic = {}
869 869 pwprofileObjDic = {}
870 870 showColorbar = None
871 871 showPowerProfile = None
872 872 XAxisAsTime = None
873 873 widht = None
874 874 height = None
875 875 __rtixpos = None
876 876 __rtiypos = None
877 877 __cmapxpos = None
878 878 __cmapypos = None
879 879 __profxpos = None
880 880 __profypos = None
881 881
882 882 def __init__(self,indexFig,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
883 883 self.width = 700
884 884 self.height = 150
885 885 self.showColorbar = showColorbar
886 886 self.showPowerProfile = showPowerProfile
887 887 self.XAxisAsTime = XAxisAsTime
888 888
889 889 ncol = 1
890 890 nrow = nsubplot
891 891 initMatplotlib(indexFig,ncol,nrow,winTitle,self.width,self.height)
892 892 setColormap(colormap)
893 893 self.ncol = ncol
894 894 self.nrow = nrow
895 895
896 896 def setFigure(self,indexFig):
897 897 setFigure(indexFig)
898 898
899 899 def setRtiScreenPos(self):
900 900
901 901 if self.showPowerProfile: xi = 0.07; xf = 0.65
902 902 else: xi = 0.07; xf = 0.9
903 903 yi = 0.15; yf = 0.80
904 904
905 905 xpos = [xi,xf]
906 906 ypos = [yi,yf]
907 907
908 908 self.__rtixpos = xpos
909 909 self.__rtiypos = ypos
910 910
911 911 return xpos,ypos
912 912
913 913 def setColorbarScreenPos(self):
914 914
915 915 xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03
916 916
917 917 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
918 918
919 919 xpos = [xi,xf]
920 920 ypos = [yi,yf]
921 921
922 922 self.__cmapxpos = xpos
923 923 self.__cmapypos = ypos
924 924
925 925 return xpos,ypos
926 926
927 927 def setPowerprofileScreenPos(self):
928 928
929 929 xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20
930 930
931 931 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
932 932
933 933 xpos = [xi,xf]
934 934 ypos = [yi,yf]
935 935
936 936 self.__profxpos = [xi,xf]
937 937 self.__profypos = [yi,yf]
938 938
939 939 return xpos,ypos
940 940
941 941 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone='lt',npoints=100):
942 942 # Config Rti plot
943 943 szchar = 1.10
944 944 name = 'rti'
945 945 key = name + '%d'%subplot
946 946
947 947 # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal]
948 948 thisDateTime = datetime.datetime.fromtimestamp(timedata)
949 949 startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0)
950 950 endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59)
951 951 deltaTime = 0
952 952 if timezone == 'lt':
953 953 deltaTime = time.timezone
954 954 startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime
955 955 endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime
956 956
957 957 xrange = [startTimeInSecs,endTimeInSecs]
958 958 totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1.
959 959 deltax = totalTimeInXrange / npoints
960 960
961 961 yrange = [ymin,ymax]
962 962 zrange = [zmin,zmax]
963 963
964 964 xpos,ypos = self.setRtiScreenPos()
965 965 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax)
966 966 if self.XAxisAsTime:
967 967 pcolorObj.setXAxisAsTime(self.XAxisAsTime)
968 968 xopt = 'bcnstd'
969 969 yopt = 'bcnstv'
970 970 else:
971 971 xopt = 'bcnst'
972 972 yopt = 'bcnstv'
973 973
974 974 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
975 975 self.pcolorObjDic[key] = pcolorObj
976 976
977 977
978 978 # Config Colorbar
979 979 if self.showColorbar:
980 980 szchar = 0.9
981 981 name = 'colorbar'
982 982 key = name + '%d'%subplot
983 983
984 984 xpos,ypos = self.setColorbarScreenPos()
985 985 xrange = [0.,1.]
986 986 yrange = [zmin,zmax]
987 987 cmapObj = BaseGraph(name,subplot,xpos,ypos,'','','dB',szchar,xrange,yrange)
988 988 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcm')
989 989 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
990 990 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], 'bc', 'bcmtsv')
991 991 self.colorbarObjDic[key] = cmapObj
992 992
993 993
994 994 # Config Power profile
995 995 if self.showPowerProfile:
996 996 szchar = 0.8
997 997 name = 'pwprofile'
998 998 key = name + '%d'%subplot
999 999
1000 1000 xpos,ypos = self.setPowerprofileScreenPos()
1001 1001 xrange = [zmin,zmax]
1002 1002 yrange = [ymin,ymax]
1003 1003 powObj = BaseGraph(name,subplot,xpos,ypos,'dB','','Power Profile',szchar,xrange,yrange)
1004 1004 powObj.setLineStyle(2)
1005 1005 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
1006 1006 powObj.setLineStyle(1)
1007 1007 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
1008 1008 self.pwprofileObjDic[key] = powObj
1009 1009
1010 1010
1011 1011 def plot(self,subplot,x,y,z):
1012 1012 # RTI plot
1013 1013 name = 'rti'
1014 1014 key = name + '%d'%subplot
1015 1015
1016 1016 data = numpy.reshape(z, (1,-1))
1017 1017 data = numpy.abs(data)
1018 1018 data = 10*numpy.log10(data)
1019 1019 newx = [x,x+1]
1020 1020
1021 1021 pcolorObj = self.pcolorObjDic[key]
1022 1022
1023 1023 if pcolorObj.xaxisIsTime:
1024 1024 xopt = 'bcstd'
1025 1025 yopt = 'bcst'
1026 1026 else:
1027 1027 xopt = 'bcst'
1028 1028 yopt = 'bcst'
1029 1029
1030 1030 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
1031 1031
1032 1032 deltax = pcolorObj.deltax
1033 1033 deltay = None
1034 1034
1035 1035 if pcolorObj.xmin == None and pcolorObj.xmax == None:
1036 1036 pcolorObj.xmin = x
1037 1037 pcolorObj.xmax = x
1038 1038
1039 1039 if x >= pcolorObj.xmax:
1040 1040 xmin = x
1041 1041 xmax = x + deltax
1042 1042 x = [x]
1043 1043 pcolorObj.advPcolorPlot(data,
1044 1044 x,
1045 1045 y,
1046 1046 xmin=xmin,
1047 1047 xmax=xmax,
1048 1048 ymin=pcolorObj.yrange[0],
1049 1049 ymax=pcolorObj.yrange[1],
1050 1050 zmin=pcolorObj.zrange[0],
1051 1051 zmax=pcolorObj.zrange[1],
1052 1052 deltax=deltax,
1053 1053 deltay=deltay,
1054 1054 getGrid=pcolorObj.getGrid)
1055 1055
1056 1056 pcolorObj.xmin = xmin
1057 1057 pcolorObj.xmax = xmax
1058 1058
1059 1059
1060 1060 # Power Profile
1061 1061 if self.showPowerProfile:
1062 1062 data = numpy.reshape(data,(numpy.size(data)))
1063 1063 name = 'pwprofile'
1064 1064 key = name + '%d'%subplot
1065 1065 powObj = self.pwprofileObjDic[key]
1066 1066
1067 1067 if powObj.setXYData() != None:
1068 1068 clearData(powObj)
1069 1069 powObj.setLineStyle(2)
1070 1070 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bcntg', 'bc')
1071 1071 powObj.setLineStyle(1)
1072 1072 else:
1073 1073 powObj.setXYData(data,y)
1074 1074
1075 1075 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], 'bc', 'bc')
1076 1076 powObj.basicXYPlot(data,y)
1077 1077 powObj.setXYData(data,y)
1078 1078
1079 1079 def savePlot(self,indexFig,filename):
1080 1080
1081 1081 width = self.width*self.ncol
1082 1082 hei = self.height*self.nrow
1083 1083 savePlplot(filename,width,hei)
1084 1084
1085 1085 def refresh(self):
1086 1086 refresh()
1087 1087
1088 1088
1089 1089 if __name__ == '__main__':
1090 1090
1091 1091 """
1092 1092 Ejemplo1
1093 1093 """
1094 1094 #Setting the signal
1095 1095 fs = 8000
1096 1096 f0 = 200
1097 1097 f1 = 400
1098 1098 T = 1./fs
1099 1099 x = numpy.arange(160)
1100 1100 y1 = numpy.sin(2*numpy.pi*f0*x*T)
1101 1101 y2 = numpy.sin(2*numpy.pi*f1*x*T)
1102 1102 signalList = [y1,y2]
1103 1103
1104 1104 xmin = numpy.min(x)
1105 1105 xmax = numpy.max(x)
1106 1106 ymin = numpy.min(y1)
1107 1107 ymax = numpy.max(y1)
1108 1108
1109 1109 # Creating Object
1110 1110 indexPlot = 1
1111 1111 nsubplot = 2
1112 1112 winTitle = "mi grafico v1"
1113 1113
1114 1114 subplotTitle = "subplot - No."
1115 1115 xlabel = ""
1116 1116 ylabel = ""
1117 1117
1118 1118 linearObj = LinearPlot(indexPlot,nsubplot,winTitle)
1119 1119
1120 1120 #Config SubPlots
1121 1121 for subplot in range(nsubplot):
1122 1122 indexplot = subplot + 1
1123 1123 title = subplotTitle + '%d'%indexplot
1124 1124 linearObj.setup(indexplot, xmin, xmax, ymin, ymax, title, xlabel, ylabel)
1125 1125
1126 1126 #Plotting
1127 1127 type = "simple"
1128 1128 for subplot in range(nsubplot):
1129 1129 indexplot = subplot + 1
1130 1130 y = signalList[subplot]
1131 1131 linearObj.plot(indexplot, x, y, type)
1132 1132
1133 1133 linearObj.refresh()
1134 linearObj.show()
1134 # linearObj.show()
1135 1135
1136 1136
1137 # """
1138 # Ejemplo2
1139 # """
1140 #
1141 # # make these smaller to increase the resolution
1142 # dx, dy = 0.05, 0.05
1143 # x = numpy.arange(-3.0, 3.0001, dx)
1144 # y = numpy.arange(-2.0, 2.0001, dy)
1145 ## X,Y = numpy.meshgrid(x, y)
1146 # X,Y = sn.ndgrid(x, y)
1147 # Z = (1- X/2 + X**5 + Y**3)*numpy.exp(-X**2-Y**2)
1148 #
1149 # # Creating Object
1150 # indexPlot = 2
1151 # nsubplot = 1
1152 # winTitle = "mi grafico pcolor"
1153 # colormap = "br_green"
1154 # showColorbar = True
1155 # showPowerProfile = False
1156 # XAxisAsTime = False
1157 #
1158 # subplotTitle = "subplot no. "
1159 # xlabel = ""
1160 # ylabel = ""
1161 #
1162 # xmin = -3.0
1163 # xmax = 3.0
1164 # ymin = -2.0
1165 # ymax = 2.0
1166 # zmin = -0.3
1167 # zmax = 1.0
1168 #
1169 # isPlotIni = False
1170 # isPlotConfig = False
1171 # ntimes = 10
1172 #
1173 #
1174 # for i in range(ntimes):
1175 #
1176 # # Instancia del objeto
1177 # if not(isPlotConfig):
1178 # pcolorObj = PcolorPlot(indexPlot, nsubplot, winTitle, colormap, showColorbar, showPowerProfile, XAxisAsTime)
1179 # isPlotConfig = True
1180 #
1181 # # Crea los subplots
1182 # if not(isPlotIni):
1183 # for index in range(nsubplot):
1184 # indexplot = index + 1
1185 # title = subplotTitle + '%d'%indexplot
1186 # subplot = index
1187 # pcolorObj.createObjects(indexplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
1188 # isPlotIni = True
1189 #
1190 # # Inicializa el grafico en cada iteracion
1191 # pcolorObj.setFigure(indexPlot)
1192 # pcolorObj.setNewPage("")
1193 #
1194 # for index in range(nsubplot):
1195 # subplot = index
1196 # pcolorObj.iniPlot(subplot+1)
1197 #
1198 # #plotea los datos
1199 # for channel in range(nsubplot):
1200 # data = Z+0.1*numpy.random.randn(len(x),len(y))
1201 # pcolorObj.plot(channel+1, x, y, data)
1202 #
1203 # pcolorObj.refresh()
1204 #
1205 ## pcolorObj.closePage() #descomentar esta linea para mas iteraciones
1206 #
1207 # time.sleep(1)
1208 #
1209 # pcolorObj.show()
1210 #
1211 # print "end" No newline at end of file
1137 """
1138 Ejemplo2
1139 """
1140
1141 # make these smaller to increase the resolution
1142 dx, dy = 0.05, 0.05
1143 x = numpy.arange(-3.0, 3.0001, dx)
1144 y = numpy.arange(-2.0, 2.0001, dy)
1145 # X,Y = numpy.meshgrid(x, y)
1146 X,Y = sn.ndgrid(x, y)
1147 Z = (1- X/2 + X**5 + Y**3)*numpy.exp(-X**2-Y**2)
1148
1149 # Creating Object
1150 indexPlot = 2
1151 nsubplot = 1
1152 winTitle = "mi grafico pcolor"
1153 colormap = "br_green"
1154 showColorbar = True
1155 showPowerProfile = False
1156 XAxisAsTime = False
1157
1158 subplotTitle = "subplot no. "
1159 xlabel = ""
1160 ylabel = ""
1161
1162 xmin = -3.0
1163 xmax = 3.0
1164 ymin = -2.0
1165 ymax = 2.0
1166 zmin = -0.3
1167 zmax = 1.0
1168
1169 isPlotIni = False
1170 isPlotConfig = False
1171 ntimes = 10
1172
1173
1174 for i in range(ntimes):
1175
1176 # Instancia del objeto
1177 if not(isPlotConfig):
1178 pcolorObj = PcolorPlot(indexPlot, nsubplot, winTitle, colormap, showColorbar, showPowerProfile, XAxisAsTime)
1179 isPlotConfig = True
1180
1181 # Crea los subplots
1182 if not(isPlotIni):
1183 for index in range(nsubplot):
1184 indexplot = index + 1
1185 title = subplotTitle + '%d'%indexplot
1186 subplot = index
1187 pcolorObj.createObjects(indexplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
1188 isPlotIni = True
1189
1190 # Inicializa el grafico en cada iteracion
1191 pcolorObj.setFigure(indexPlot)
1192 pcolorObj.setNewPage("")
1193
1194 for index in range(nsubplot):
1195 subplot = index
1196 pcolorObj.iniPlot(subplot+1)
1197
1198 #plotea los datos
1199 for channel in range(nsubplot):
1200 data = Z+0.1*numpy.random.randn(len(x),len(y))
1201 pcolorObj.plot(channel+1, x, y, data)
1202
1203 pcolorObj.refresh()
1204
1205 # pcolorObj.closePage() #descomentar esta linea para mas iteraciones
1206
1207 time.sleep(1)
1208
1209 pcolorObj.show()
1210
1211 print "end" No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now