##// END OF EJS Templates
Paquete de graficos para signal chain, este paqquete contiene un nuevo diseno de objetos: Figure, Frame y Plot. Se considera tambien el uso de driver para plplot y matplotlib
Daniel Valdez -
r133:305399c01034
parent child
Show More
@@ -0,0 +1,272
1
2 import numpy
3 import schainPlplotLib
4
5 class Figure:
6
7 __driverObj = None
8 __isDriverOpen = False
9 __isFigureOpen = False
10 __isConfig = False
11 __xw = None
12 __yw = None
13
14 xmin = None
15 xmax = None
16 minvalue = None
17 maxvalue = None
18
19 idfigure = None
20 nframes = None
21 wintitle = wintitle
22 colormap = None
23 driver = None
24 overplot = None
25
26 frameObjList = []
27
28 def __init__(self, idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, *showGraphs):
29
30 self.driver = driver
31 self.idfigure = idfigure
32 self.nframes = nframes
33 self.wintitle = wintitle
34 self.overplot = overplot
35 self.colormap = colormap
36
37 self.showGraph1 = showGraphs[0]
38 self.showGraph2 = showGraphs[1]
39 self.__xw = xw
40 self.__yw = yw
41
42 self.__driverObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs)
43
44 self.__driverObj.driver.configDriver()
45
46
47 def __openDriver(self):
48
49 self.__driverObj.driver.openDriver()
50
51 def __openFigure(self):
52
53 nrows, ncolumns = self.getSubplots()
54
55 self.__driverObj.driver.openFigure()
56 self.__driverObj.driver.setSubPlots(nrows, ncolumns)
57
58
59 def __isOutOfXRange(self, x):
60 pass
61
62 def __changeXRange(self, x):
63 pass
64
65 def __createFrames(self):
66
67 for frame in range(self.nframes):
68 frameObj = Frame(idframe = frame,
69 showGraph1 = self.showGraph1,
70 showGraph2 = self.showGraph2
71 )
72
73 self.frameObjList.append(frameObj)
74
75 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvlaue=None, save=False, gpath='./'):
76
77 nx, ny = data1D.shape
78
79 if channelList == None:
80 chanellList = range(nx)
81
82 if x == None:
83 x = numpy.arange(data1D.size)
84
85
86
87
88 if not(self.__isDriverOpen):
89 self.__openDriver()
90 self.__isDriverOpen = True
91
92 if not(self.__isConfig):
93 if self.xmin == None: xmin = numpy.min(x)
94 if self.xmax == None: xmax = numpy.max(x)
95 if self.minvalue == None: minvalue = numpy.min(data1D)
96 if self.maxvalue == None: maxvalue = numpy.max(data1D)
97
98 self.__createFrames()
99 self.__isConfig = True
100
101
102 if not(self.__isOutOfXRange(x)):
103 self.__changeXRange(x)
104
105 if self.__isFigureOpen:
106 self.__driverObj.closePage()
107 self.__isFigureOpen = False
108
109 if not(self.__isFigureOpen):
110 self.__openFigure()
111
112 for channel in channelList:
113 frameObj = self.frameObjList[channel]
114 frameObj.init(xmin=xmin,
115 xmax=xmax,
116 minvalue=minvalue,
117 maxvalue=maxvalue)
118
119 self.__isFigureOpen = True
120
121
122 for channel in channelList:
123 dataCh = data1D[channel]
124 frameObj = self.frameObjList[channel]
125
126 frameObj.clearData()
127 frameObj.plot(dataCh)
128
129 frameObj.refresh()
130
131 if not(self.overplot):
132 self.__driverObj.closeFigure()
133 self.__isFigureOpen = False
134
135
136 def plot2DArray(self, x, y, data2D, xmin=None, xmax=None, ymin=None, ymax=None, minvalue=None, maxvalue=None, save=False, gpath='./'):
137
138 if not(self.__isCOpen):
139 self.__createFrames()
140 self.__openFigure()
141 self.__isOpen = True
142
143 if not(self.__isConfig):
144 self.setRange(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, minvalue=minvalue, maxvalue=maxvalue)
145
146 self.__isConfig = True
147
148 for channel in channelList:
149 dataCh = dataArray[channel]
150 frameObj = frameObjList[channel]
151 frameObj.plot(dataCh)
152
153 def saveFigure(self, filename):
154 pass
155
156
157 def getSubplots(self):
158
159 raise ValueError, "No implemented"
160
161 class Frame:
162
163 """
164 subplots
165 """
166
167 plotObjList = []
168 title = ""
169 def __init__(self, idframe, showGraph1=False, showGraph2=False):
170
171 self.idframe = idframe
172 self.showGraph1 = showGraph1
173 self.showGraph2 = showGraph2
174
175 self.nplots = 1 + showGraph1 + showGraph2#para el caso de RTI showGrap1 deberia indicar colorbar como propiedad, no como plot
176 self.__createPlots()
177
178 def __createPlots(self):
179
180 for nplot in range(self.nplots):
181 xi, yi, xw, yw = self.__getScreenPos(nplot)
182 plotObj = Plot(xi, yi, xw, yw)
183
184 self.plotObjList.append(plotObj)
185
186 def __getScreenPosMainPlot(self):
187
188 """
189 Calcula las coordenadas asociadas al plot principal.
190 """
191
192 xi = 1.2
193 yi = 2.3
194 xw = 2.0
195 yw = 1.4
196
197 return xi, yi, xw, yw
198
199 def __getScreenPosGraph1(self):
200 xi = 1.2
201 yi = 2.3
202 xw = 2.0
203 yw = 1.4
204
205 return xi, yi, xw, yw
206
207 def __getScreenPosGraph2(self):
208 xi = 1.2
209 yi = 2.3
210 xw = 2.0
211 yw = 1.4
212
213 return xi, yi, xw, yw
214
215 def __getScreenPos(self, nplot):
216
217 if nplot == 0:
218 xi, yi, xw, yw = self.__getScreenPosMain()
219 if nplot == 1:
220 xi, yi, xw, yw = self.__getScreenPosMain()
221 if nplot == 2:
222 xi, yi, xw, yw = self.__getScreenPosMain()
223
224 return xi, yi, xw, yw
225
226
227 def init(self, xmin, xmax, ymin, yamx, minvalue, maxvalue):
228
229 """
230 """
231
232 for plotObj in self.plotObjList:
233 plotObj.plotBox(xmin, xmax, ymin, yamx, minvalue, maxvalue)
234
235 def clearData(self):
236 pass
237
238 def plot(self, data):
239
240 for plotObj in self.plotObjList:
241 plotObj.plotData(data)
242
243 def refresh(self):
244 pass
245
246
247
248 class Plot:
249
250 title = ""
251
252 def __init__(self, xi, yi, xw, yw):
253
254 self.xi = xi
255 self.yi = yi
256 self.xw = xw
257 self.yw = yw
258
259 def __setRange(self, xrange, yrange, zrange):
260 pass
261
262 def __setLabels(self, xlabel, ylabel, zlabel):
263 pass
264
265
266 def plotBox(self,xmin, xmax, ymin, yamx, minvalue, maxvalue):
267 pass
268
269 def plotData(self):
270
271 raise ValueError, ""
272
This diff has been collapsed as it changes many lines, (680 lines changed) Show them Hide them
@@ -0,0 +1,680
1 import plplot
2 import numpy
3 import sys
4 import plplot #condicional
5
6 class Driver:
7 def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs):
8 if driver == "plplot":
9 self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs)
10 elif driver == "mpl":
11 self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, *showGraphs)
12 else:
13 raise ValueError, "The driver: %s is not defined"%driver
14
15 class PlplotDriver:
16
17 __isDriverOpen = False
18 pldriver = None
19
20 def __init__(self, idfigure=None, xw, yw, wintitle, overplot, colormap, *showGraphs):
21
22 if idfigure == None:
23 raise ValueError, 'idfigure input must be defined'
24
25 self.idfigure = idfigure
26 self.xw = xw
27 self.yw = yw
28 self.wintitle = wintitle
29 self.overplot = overplot
30 self.colormap = colormap
31 self.showGraph1 = showGraphs[0]
32 self.showGraph2 = showGraphs[1]
33
34 def configDriver(self):
35 """
36 previous configuration to open(init) the plplot driver
37 """
38 plplot.plsstrm(self.idfigure)
39 plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL)
40 plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw))
41
42 plplot.plscolbg(255,255,255)
43 plplot.plscol0(1,0,0,0)
44
45 def openDriver(self, pldriver=None):
46 if pldriver == None:
47 if sys.platform == "linux":
48 pldriver = "xcairo"
49
50 elif sys.platform == "darwin":
51 pldriver = "xwin"
52
53 else:
54 pldriver = ""
55
56 plplot.plsdev(pldriver)
57 plplot.plinit()
58 plplot.plspause(False)
59
60 self.pldriver = pldriver
61
62 def closeDriver(self):
63 pass
64
65 def openPage(self):
66 plplot.plbop()
67 plplot.pladv(0)
68
69 def closePage(self):
70 plplot.pleop()
71
72 def openFigure(self):
73 plplot.plbop()
74 plplot.pladv(0)
75
76 def closeFigure(self):
77 plplot.pleop()
78
79 def setSubPlots(self,nrows, ncolumns):
80 plplot.plssub(nrows, ncolumns)
81
82 def setColorMap(self,colormap):
83
84 if colormap == None:
85 return
86
87 ncolor = None
88 rgb_lvl = None
89
90 # Routine for defining a specific color map 1 in HLS space.
91 # if gray is true, use basic grayscale variation from half-dark to light.
92 # otherwise use false color variation from blue (240 deg) to red (360 deg).
93
94 # Independent variable of control points.
95
96 i = numpy.array((0., 1.))
97
98 if colormap=="gray":
99 ncolor = 256
100 # Hue for control points. Doesn't matter since saturation is zero.
101 h = numpy.array((0., 0.))
102 # Lightness ranging from half-dark (for interest) to light.
103 l = numpy.array((0.5, 1.))
104 # Gray scale has zero saturation
105 s = numpy.array((0., 0.))
106
107 # number of cmap1 colours is 256 in this case.
108 plplot.plscmap1n(ncolor)
109 # Interpolate between control points to set up cmap1.
110 plplot.plscmap1l(0, i, h, l, s)
111
112 return None
113
114 if colormap == 'jet':
115 ncolor = 256
116 pos = numpy.zeros((ncolor))
117 r = numpy.zeros((ncolor))
118 g = numpy.zeros((ncolor))
119 b = numpy.zeros((ncolor))
120
121 for i in range(ncolor):
122 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
123 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
124 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
125 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
126
127 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
128 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
129 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
130 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
131 else: gf = 0.0
132
133 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
134 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
135 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
136 else: bf = 0
137
138 r[i] = rf
139 g[i] = gf
140 b[i] = bf
141
142 pos[i] = float(i)/float(ncolor-1)
143
144
145 plplot.plscmap1n(ncolor)
146 plplot.plscmap1l(1, pos, r, g, b)
147
148
149
150 if colormap=="br_green":
151 ncolor = 256
152 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
153 h = numpy.array((240., 0.))
154 # Lightness and saturation are constant (values taken from C example).
155 l = numpy.array((0.6, 0.6))
156 s = numpy.array((0.8, 0.8))
157
158 # number of cmap1 colours is 256 in this case.
159 plplot.plscmap1n(ncolor)
160 # Interpolate between control points to set up cmap1.
161 plplot.plscmap1l(0, i, h, l, s)
162
163 return None
164
165 if colormap=="tricolor":
166 ncolor = 3
167 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
168 h = numpy.array((240., 0.))
169 # Lightness and saturation are constant (values taken from C example).
170 l = numpy.array((0.6, 0.6))
171 s = numpy.array((0.8, 0.8))
172
173 # number of cmap1 colours is 256 in this case.
174 plplot.plscmap1n(ncolor)
175 # Interpolate between control points to set up cmap1.
176 plplot.plscmap1l(0, i, h, l, s)
177
178 return None
179
180 if colormap == 'rgb' or colormap == 'rgb666':
181
182 color_sz = 6
183 ncolor = color_sz*color_sz*color_sz
184 pos = numpy.zeros((ncolor))
185 r = numpy.zeros((ncolor))
186 g = numpy.zeros((ncolor))
187 b = numpy.zeros((ncolor))
188 ind = 0
189 for ri in range(color_sz):
190 for gi in range(color_sz):
191 for bi in range(color_sz):
192 r[ind] = ri/(color_sz-1.0)
193 g[ind] = gi/(color_sz-1.0)
194 b[ind] = bi/(color_sz-1.0)
195 pos[ind] = ind/(ncolor-1.0)
196 ind += 1
197 rgb_lvl = [6,6,6] #Levels for RGB colors
198
199 if colormap == 'rgb676':
200 ncolor = 6*7*6
201 pos = numpy.zeros((ncolor))
202 r = numpy.zeros((ncolor))
203 g = numpy.zeros((ncolor))
204 b = numpy.zeros((ncolor))
205 ind = 0
206 for ri in range(8):
207 for gi in range(8):
208 for bi in range(4):
209 r[ind] = ri/(6-1.0)
210 g[ind] = gi/(7-1.0)
211 b[ind] = bi/(6-1.0)
212 pos[ind] = ind/(ncolor-1.0)
213 ind += 1
214 rgb_lvl = [6,7,6] #Levels for RGB colors
215
216 if colormap == 'rgb685':
217 ncolor = 6*8*5
218 pos = numpy.zeros((ncolor))
219 r = numpy.zeros((ncolor))
220 g = numpy.zeros((ncolor))
221 b = numpy.zeros((ncolor))
222 ind = 0
223 for ri in range(8):
224 for gi in range(8):
225 for bi in range(4):
226 r[ind] = ri/(6-1.0)
227 g[ind] = gi/(8-1.0)
228 b[ind] = bi/(5-1.0)
229 pos[ind] = ind/(ncolor-1.0)
230 ind += 1
231 rgb_lvl = [6,8,5] #Levels for RGB colors
232
233 if colormap == 'rgb884':
234 ncolor = 8*8*4
235 pos = numpy.zeros((ncolor))
236 r = numpy.zeros((ncolor))
237 g = numpy.zeros((ncolor))
238 b = numpy.zeros((ncolor))
239 ind = 0
240 for ri in range(8):
241 for gi in range(8):
242 for bi in range(4):
243 r[ind] = ri/(8-1.0)
244 g[ind] = gi/(8-1.0)
245 b[ind] = bi/(4-1.0)
246 pos[ind] = ind/(ncolor-1.0)
247 ind += 1
248 rgb_lvl = [8,8,4] #Levels for RGB colors
249
250 if ncolor == None:
251 raise ValueError, "The colormap selected is not valid"
252
253 plplot.plscmap1n(ncolor)
254 plplot.plscmap1l(1, pos, r, g, b)
255
256 return rgb_lvl
257
258 def setBox(self):
259
260 pass
261
262 def refreshBox(self):
263
264 pass
265
266 def save(self):
267
268 pass
269
270 def show(self):
271
272 pass
273
274 def colorbarPlot(self):
275
276 pass
277
278 def linePlot(self):
279
280 pass
281
282 def pcolorPlot(self):
283
284 pass
285
286 def setLabels(self):
287
288 pass
289
290
291
292
293
294 class MplDriver:
295 def __init__(self):
296 pass
297
298 def config_driver(idfigure, wintitle, width, height):
299 plplot.plsstrm(idfigure)
300 plplot.plparseopts([wintitle],plplot.PL_PARSE_FULL)
301 plplot.plsetopt("geometry", "%dx%d"%(width,height))
302
303 def ini_driver(driver):
304 if sys.platform == "darwin":
305 plplot.plsdev("xwin")
306 if sys.platform == "linux":
307 plplot.plsdev("xcairo")
308 plplot.plscolbg(255,255,255)
309 plplot.plscol0(1,0,0,0)
310 plplot.plinit()
311 plplot.plspause(False)
312
313 def set_subpages(ncol,nrow):
314 plplot.plssub(ncol,nrow)
315
316 def cmap1_init(colormap="gray"):
317
318 if colormap == None:
319 return
320
321 ncolor = None
322 rgb_lvl = None
323
324 # Routine for defining a specific color map 1 in HLS space.
325 # if gray is true, use basic grayscale variation from half-dark to light.
326 # otherwise use false color variation from blue (240 deg) to red (360 deg).
327
328 # Independent variable of control points.
329 i = numpy.array((0., 1.))
330 if colormap=="gray":
331 ncolor = 256
332 # Hue for control points. Doesn't matter since saturation is zero.
333 h = numpy.array((0., 0.))
334 # Lightness ranging from half-dark (for interest) to light.
335 l = numpy.array((0.5, 1.))
336 # Gray scale has zero saturation
337 s = numpy.array((0., 0.))
338
339 # number of cmap1 colours is 256 in this case.
340 plplot.plscmap1n(ncolor)
341 # Interpolate between control points to set up cmap1.
342 plplot.plscmap1l(0, i, h, l, s)
343
344 return None
345
346 if colormap == 'jet':
347 ncolor = 256
348 pos = numpy.zeros((ncolor))
349 r = numpy.zeros((ncolor))
350 g = numpy.zeros((ncolor))
351 b = numpy.zeros((ncolor))
352
353 for i in range(ncolor):
354 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
355 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
356 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
357 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
358
359 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
360 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
361 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
362 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
363 else: gf = 0.0
364
365 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
366 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
367 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
368 else: bf = 0
369
370 r[i] = rf
371 g[i] = gf
372 b[i] = bf
373
374 pos[i] = float(i)/float(ncolor-1)
375
376
377 plplot.plscmap1n(ncolor)
378 plplot.plscmap1l(1, pos, r, g, b)
379
380
381
382 if colormap=="br_green":
383 ncolor = 256
384 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
385 h = numpy.array((240., 0.))
386 # Lightness and saturation are constant (values taken from C example).
387 l = numpy.array((0.6, 0.6))
388 s = numpy.array((0.8, 0.8))
389
390 # number of cmap1 colours is 256 in this case.
391 plplot.plscmap1n(ncolor)
392 # Interpolate between control points to set up cmap1.
393 plplot.plscmap1l(0, i, h, l, s)
394
395 return None
396
397 if colormap=="tricolor":
398 ncolor = 3
399 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
400 h = numpy.array((240., 0.))
401 # Lightness and saturation are constant (values taken from C example).
402 l = numpy.array((0.6, 0.6))
403 s = numpy.array((0.8, 0.8))
404
405 # number of cmap1 colours is 256 in this case.
406 plplot.plscmap1n(ncolor)
407 # Interpolate between control points to set up cmap1.
408 plplot.plscmap1l(0, i, h, l, s)
409
410 return None
411
412 if colormap == 'rgb' or colormap == 'rgb666':
413
414 color_sz = 6
415 ncolor = color_sz*color_sz*color_sz
416 pos = numpy.zeros((ncolor))
417 r = numpy.zeros((ncolor))
418 g = numpy.zeros((ncolor))
419 b = numpy.zeros((ncolor))
420 ind = 0
421 for ri in range(color_sz):
422 for gi in range(color_sz):
423 for bi in range(color_sz):
424 r[ind] = ri/(color_sz-1.0)
425 g[ind] = gi/(color_sz-1.0)
426 b[ind] = bi/(color_sz-1.0)
427 pos[ind] = ind/(ncolor-1.0)
428 ind += 1
429 rgb_lvl = [6,6,6] #Levels for RGB colors
430
431 if colormap == 'rgb676':
432 ncolor = 6*7*6
433 pos = numpy.zeros((ncolor))
434 r = numpy.zeros((ncolor))
435 g = numpy.zeros((ncolor))
436 b = numpy.zeros((ncolor))
437 ind = 0
438 for ri in range(8):
439 for gi in range(8):
440 for bi in range(4):
441 r[ind] = ri/(6-1.0)
442 g[ind] = gi/(7-1.0)
443 b[ind] = bi/(6-1.0)
444 pos[ind] = ind/(ncolor-1.0)
445 ind += 1
446 rgb_lvl = [6,7,6] #Levels for RGB colors
447
448 if colormap == 'rgb685':
449 ncolor = 6*8*5
450 pos = numpy.zeros((ncolor))
451 r = numpy.zeros((ncolor))
452 g = numpy.zeros((ncolor))
453 b = numpy.zeros((ncolor))
454 ind = 0
455 for ri in range(8):
456 for gi in range(8):
457 for bi in range(4):
458 r[ind] = ri/(6-1.0)
459 g[ind] = gi/(8-1.0)
460 b[ind] = bi/(5-1.0)
461 pos[ind] = ind/(ncolor-1.0)
462 ind += 1
463 rgb_lvl = [6,8,5] #Levels for RGB colors
464
465 if colormap == 'rgb884':
466 ncolor = 8*8*4
467 pos = numpy.zeros((ncolor))
468 r = numpy.zeros((ncolor))
469 g = numpy.zeros((ncolor))
470 b = numpy.zeros((ncolor))
471 ind = 0
472 for ri in range(8):
473 for gi in range(8):
474 for bi in range(4):
475 r[ind] = ri/(8-1.0)
476 g[ind] = gi/(8-1.0)
477 b[ind] = bi/(4-1.0)
478 pos[ind] = ind/(ncolor-1.0)
479 ind += 1
480 rgb_lvl = [8,8,4] #Levels for RGB colors
481
482 if ncolor == None:
483 raise ValueError, "The colormap selected is not valid"
484
485 plplot.plscmap1n(ncolor)
486 plplot.plscmap1l(1, pos, r, g, b)
487
488 return rgb_lvl
489
490 def set_colormap(colormap="jet"):
491 cmap1_init(colormap)
492
493 def save_figure(filename,width,height):
494 curr_strm = plplot.plgstrm()
495 save_strm = plplot.plmkstrm()
496 plplot.plsetopt("geometry", "%dx%d"%(width,height))
497 if sys.platform == "darwin":
498 plplot.plsdev("png")
499 if sys.platform == "linux":
500 plplot.plsdev("pngcairo")
501 plplot.plsfnam(filename)
502 plplot.plcpstrm(curr_strm,0)
503 plplot.plreplot()
504 plplot.plend1()
505 plplot.plsstrm(curr_strm)
506
507 def set_new_figure():
508 plplot.plbop()
509 plplot.pladv(0)
510
511 def close_figure():
512 plplot.pleop()
513
514 def set_strm(indexPlot):
515 plplot.plsstrm(indexPlot)
516
517 def refresh():
518 plplot.plflush()
519
520 def show():
521 plplot.plspause(True)
522 plplot.plend()
523
524 def set_title(pltitle,color, szchar=0.7):
525 setSubpages(1, 0)
526 plplot.pladv(0)
527 plplot.plvpor(0., 1., 0., 1.)
528
529 if color == "black":
530 plplot.plcol0(1)
531 if color == "white":
532 plplot.plcol0(15)
533
534 plplot.plschr(0.0,szchar)
535 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
536
537 def set_line_style(style):
538 plplot.pllsty(style)
539
540 def set_color(color):
541 plplot.plcol0(color)
542
543 def set_labels(xlabel, ylabel, title):
544 plplot.pllab(xlabel, ylabel, title)
545
546 def box(subplot, xpos, ypos, xmin, xmax, ymin, ymax, xopt, yopt, szchar, xaxisastime, timefmt="%H:%M"):
547 plplot.pladv(subplot)
548 plplot.plschr(0.0,szchar-0.05)
549 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
550 plplot.plwind(float(xmin),
551 float(xmax),
552 float(ymin),
553 float(ymax)
554 )
555 if xaxisastime:
556 plplot.pltimefmt(timefmt)
557 timedelta = (xmax - xmin + 1)/8.
558 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
559 else:
560 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
561
562 def colorbar(xmin=0., xmax=1., ymin=0., ymax=1.):
563 data = numpy.arange(256)
564 data = numpy.reshape(data, (1,-1))
565
566 plplot.plimage(data,
567 float(xmin),
568 float(xmax),
569 float(ymin),
570 float(ymax),
571 0.,
572 255.,
573 float(xmin),
574 float(xmax),
575 float(ymin),
576 float(ymax))
577
578 def basicline_timeplot(x, y,colline=1):
579 plplot.plcol0(colline)
580 plplot.plline(x, y)
581 plplot.plcol0(1)
582
583 def basic_xy_plot(x, y):
584 plplot.plline(x, y)
585
586 def basic_pcolor_plot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
587 """
588 """
589 if xmin == None: xmin = x[0]
590 if xmax == None: xmax = x[-1]
591 if ymin == None: ymin = y[0]
592 if ymax == None: ymax = y[-1]
593 if zmin == None: zmin = numpy.nanmin(data)
594 if zmax == None: zmax = numpy.nanmax(data)
595
596 plplot.plimage(data,
597 float(x[0]),
598 float(x[-1]),
599 float(y[0]),
600 float(y[-1]),
601 float(zmin),
602 float(zmax),
603 float(xmin),
604 float(xmax),
605 float(ymin),
606 float(ymax)
607 )
608
609 def image_plot(self,x,y,z,xrange,yrange,zrange):
610 xi = x[0]
611 xf = x[-1]
612 yi = y[0]
613 yf = y[-1]
614
615 plplot.plimage(z,
616 float(xi),
617 float(xf),
618 float(yi),
619 float(yf),
620 float(zrange[0]),
621 float(zrange[1]),
622 float(xi),
623 float(xf),
624 float(yrange[0]),
625 yrange[1])
626
627 def adv_pcolor_plot(data, x, y, xg, yg, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0.):
628 plplot.plimagefr(data,
629 float(xmin),
630 float(xmax),
631 float(ymin),
632 float(ymax),
633 0.,
634 0.,
635 float(zmin),
636 float(zmax),
637 plplot.pltr2,
638 xg,
639 yg)
640
641 #------------------------------------
642
643 #def get_grid(x, y, deltax=None, deltay=None):
644 #
645 # if not(len(x)>0 and len(y)>0):
646 # raise ValueError, "x axis and y axis are empty"
647 #
648 # if deltax == None: deltax = x[-1] - x[-2]
649 # if deltay == None: deltay = y[-1] - y[-2]
650 #
651 # x1 = numpy.append(x, x[-1] + deltax)
652 # y1 = numpy.append(y, y[-1] + deltay)
653 #
654 # xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
655 # yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
656 #
657 # self.__xg = xg
658 # self.__yg = yg
659 #
660 # return xg, yg
661 #
662 #def advPcolorPlot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
663 # if getGrid:
664 # xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
665 # else:
666 # xg = self.__xg
667 # yg = self.__yg
668 #
669 # plplot.plimagefr(data,
670 # float(xmin),
671 # float(xmax),
672 # float(ymin),
673 # float(ymax),
674 # 0.,
675 # 0.,
676 # float(zmin),
677 # float(zmax),
678 # plplot.pltr2,
679 # xg,
680 # yg)
@@ -0,0 +1,125
1 import numpy
2 from schainPlot import *
3
4 class ScopeFigure(Figure):
5 overplot = 0
6 xw = 700
7 yw = 150
8
9 def __init__(self, idfigure, nframes, wintitle, driver):
10
11 showGraphs = (0, 0)
12
13 Figure.__init__(self,
14 idfigure=idfigure,
15 nframes = nframes,
16 wintitle=wintitle,
17 xw=self.xw,
18 yw=self.yw,
19 overplot=self.overplot,
20 driver=driver,
21 colormap=None,
22 *showGraphs)
23
24 self.nframes = nframes
25 self.showColorbar = 0
26 self.showPowerProfile = 0
27
28 def getSubplots(self):
29 nrows = self.nframes
30 ncolumns = 1
31
32 return nrows, ncolumns
33
34 def __createFrames(self):
35 for frame in range(self.nframes):
36 frameObj = ScopeFrame(idFrame = frame)
37
38 self.frameObjList.append(frameObj)
39
40
41
42 class ScopeFrame(Frame):
43 def __init__(self,idFrame):
44 self.idFrame = idFrame
45 self.showGraph1 = 0
46 self.showGraph2 = 0
47
48 def setXYPos(self):
49 pass
50
51 class RTIFigure(Figure):
52
53 overplot = 1 # igual a 1 porque el grafico es RTI, para el caso de Spectra(Spc,CrossSpc) overplot = 0
54 xw = 700
55 yw = 150
56
57
58 def __init__(self, idfigure, nframes, wintitle, driver, colormap, showColorbar, showPowerProfile):
59
60 showGraphs = (showColorbar, showPowerProfile)
61
62 Figure.__init__(self,
63 idfigure=idfigure,
64 nframes = nframes,
65 wintitle=wintitle,
66 xw=self.xw,
67 yw=self.yw,
68 overplot=self.overplot,
69 driver=driver,
70 colormap=colormap,
71 *showGraphs)
72
73 self.nframes = nframes
74 self.showColorbar = showColorbar
75 self.showPowerProfile = showPowerProfile
76
77 def getSubplots(self):
78 nrows = self.nframes
79 ncolumns = 1
80
81 return nrows, ncolumns
82
83 def __createFrames(self):
84 for frame in range(self.nframes):
85 frameObj = RTIFrame(idFrame = frame,
86 showGraph1 = self.showColorbar,
87 showGraph2 = self.showPowerProfile
88 )
89
90 self.frameObjList.append(frameObj)
91
92
93 class RTIFrame(Frame):
94 def __init__(self,idFrame, showColorbar, showPowerProfile):
95 self.idFrame = idFrame
96 self.showGraph1 = showColorbar
97 self.showGraph2 = showPowerProfile
98
99 def setXYPos(self):
100 pass
101
102 class SelfSpcFigure(Figure):
103 def __init__(self):
104 pass
105
106 class SelfSpcFrame(Frame):
107 def __init__(self):
108 pass
109
110 class CrossSpcFigure(Figure):
111 def __init__(self):
112 pass
113
114 class CrossSpcFrame(Frame):
115 def __init__(self):
116 pass
117
118 class ScopeFigure(Figure):
119 def __init__(self):
120 pass
121
122 class ScopeFrame(Frame):
123 def __init__(self):
124 pass
125
General Comments 0
You need to be logged in to leave comments. Login now