##// END OF EJS Templates
Adicion del metodo saveFigure() para guardar archivos de imagen de la clase Figure(). Se modifica los xaxis se muestran en formato datetime, falta hacer ajustes en los ticks de acuerdo al intervalo [xmin, xmax]
Daniel Valdez -
r209:8c431837892b
parent child
Show More
@@ -606,6 +606,8 if __name__ == '__main__':
606 # opObj11.addParameter(name='zmin', value='70', format='int')
606 # opObj11.addParameter(name='zmin', value='70', format='int')
607 # opObj11.addParameter(name='zmax', value='90', format='int')
607 # opObj11.addParameter(name='zmax', value='90', format='int')
608 opObj11.addParameter(name='showprofile', value='0', format='int')
608 opObj11.addParameter(name='showprofile', value='0', format='int')
609 opObj11.addParameter(name='save', value='1', format='int')
610 opObj11.addParameter(name='filename', value='/Users/dsuarez/Pictures/SpectraPlot.png', format='str')
609
611
610 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
612 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
611 opObj11.addParameter(name='idfigure', value='10', format='int')
613 opObj11.addParameter(name='idfigure', value='10', format='int')
@@ -104,6 +104,9 class Figure:
104 axesObj = Axes(self.fig, *args)
104 axesObj = Axes(self.fig, *args)
105 self.axesObjList.append(axesObj)
105 self.axesObjList.append(axesObj)
106
106
107 def saveFigure(self, *args):
108 self.__driver.saveFigure(self.fig, *args)
109
107 def draw(self):
110 def draw(self):
108
111
109 self.__driver.draw(self.fig)
112 self.__driver.draw(self.fig)
@@ -149,6 +152,9 class Axes:
149
152
150 self.__driver.setAxesText(self.ax, text)
153 self.__driver.setAxesText(self.ax, text)
151
154
155 def setXAxisAsTime(self):
156 pass
157
152 def pline(self, x, y,
158 def pline(self, x, y,
153 xmin=None, xmax=None,
159 xmin=None, xmax=None,
154 ymin=None, ymax=None,
160 ymin=None, ymax=None,
@@ -1,10 +1,14
1 import numpy
1 import numpy
2 import datetime
2 import matplotlib
3 import matplotlib
3 matplotlib.use("TKAgg")
4 matplotlib.use("TKAgg")
4 import matplotlib.pyplot
5 import matplotlib.pyplot
6 import matplotlib.dates
5 #import scitools.numpyutils
7 #import scitools.numpyutils
6 from mpl_toolkits.axes_grid1 import make_axes_locatable
8 from mpl_toolkits.axes_grid1 import make_axes_locatable
7
9
10 from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter
11
8 def init(idfigure, wintitle, width, height, facecolor="w"):
12 def init(idfigure, wintitle, width, height, facecolor="w"):
9
13
10 matplotlib.pyplot.ioff()
14 matplotlib.pyplot.ioff()
@@ -109,6 +113,9 def closeFigure():
109
113
110 return
114 return
111
115
116 def saveFigure(fig, filename):
117 fig.savefig(filename)
118
112 def setWinTitle(fig, title):
119 def setWinTitle(fig, title):
113
120
114 fig.canvas.manager.set_window_title(title)
121 fig.canvas.manager.set_window_title(title)
@@ -193,7 +200,7 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
193
200
194 iplot.set_data(x, y)
201 iplot.set_data(x, y)
195
202
196 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''):
203 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel='',XAxisAsTime=False):
197
204
198 divider = make_axes_locatable(ax)
205 divider = make_axes_locatable(ax)
199 ax_cb = divider.new_horizontal(size="4%", pad=0.05)
206 ax_cb = divider.new_horizontal(size="4%", pad=0.05)
@@ -201,6 +208,19 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', yla
201 fig.add_axes(ax_cb)
208 fig.add_axes(ax_cb)
202
209
203 ax.set_xlim([xmin,xmax])
210 ax.set_xlim([xmin,xmax])
211
212 if XAxisAsTime:
213 seconds = numpy.array([xmin, xmax])
214 datesList = map(datetime.datetime.fromtimestamp, seconds)
215 ax.set_xlim([datesList[0],datesList[-1]])
216 ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10)))
217 ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60)))
218 ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S"))
219 xdateList = map(datetime.datetime.fromtimestamp, x)
220 xdate = matplotlib.dates.date2num(xdateList)
221 x = xdate
222
223
204 ax.set_ylim([ymin,ymax])
224 ax.set_ylim([ymin,ymax])
205
225
206 printLabels(ax, xlabel, ylabel, title)
226 printLabels(ax, xlabel, ylabel, title)
@@ -239,8 +259,10 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
239 imesh.set_array(z.ravel())
259 imesh.set_array(z.ravel())
240
260
241 def addpcolor(ax, x, y, z, zmin, zmax):
261 def addpcolor(ax, x, y, z, zmin, zmax):
262 xdateList = map(datetime.datetime.fromtimestamp, x)
263 xdate = matplotlib.dates.date2num(xdateList)
242
264
243 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
265 imesh = ax.pcolormesh(xdate,y,z.T,vmin=zmin,vmax=zmax)
244
266
245 def draw(fig):
267 def draw(fig):
246
268
@@ -61,7 +61,7 class RTIPlot(Figure):
61 counter += 1
61 counter += 1
62
62
63 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
63 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
64 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
64 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None):
65
65
66 """
66 """
67
67
@@ -126,7 +126,7 class RTIPlot(Figure):
126 z = avg[i].reshape((1,-1))
126 z = avg[i].reshape((1,-1))
127 axes.pcolor(x, y, z,
127 axes.pcolor(x, y, z,
128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
129 xlabel=xlabel, ylabel=ylabel, title=title, rti=True,
129 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
130 ticksize=9, cblabel='')
130 ticksize=9, cblabel='')
131
131
132 if self.__showprofile:
132 if self.__showprofile:
@@ -139,6 +139,9 class RTIPlot(Figure):
139
139
140 self.draw()
140 self.draw()
141
141
142 if save:
143 self.saveFigure(filename)
144
142 class SpectraPlot(Figure):
145 class SpectraPlot(Figure):
143
146
144 __isConfig = None
147 __isConfig = None
@@ -197,7 +200,7 class SpectraPlot(Figure):
197 counter += 1
200 counter += 1
198
201
199 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
202 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
200 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
203 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None):
201
204
202 """
205 """
203
206
@@ -273,6 +276,9 class SpectraPlot(Figure):
273 grid='x')
276 grid='x')
274
277
275 self.draw()
278 self.draw()
279
280 if save:
281 self.saveFigure(filename)
276
282
277 class Scope(Figure):
283 class Scope(Figure):
278
284
@@ -304,7 +310,7 class Scope(Figure):
304 self.nplots = nplots
310 self.nplots = nplots
305
311
306 def run(self, dataOut, idfigure, wintitle="", channelList=None,
312 def run(self, dataOut, idfigure, wintitle="", channelList=None,
307 xmin=None, xmax=None, ymin=None, ymax=None):
313 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
308
314
309 """
315 """
310
316
@@ -360,5 +366,6 class Scope(Figure):
360
366
361 self.draw()
367 self.draw()
362
368
363
369 if save:
370 self.saveFigure(filename)
364 No newline at end of file
371
General Comments 0
You need to be logged in to leave comments. Login now