From 8c431837892be2766dcd91f8257bf14d8c6dded4 2012-12-03 22:49:36 From: Daniel Valdez Date: 2012-12-03 22:49:36 Subject: [PATCH] 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] --- diff --git a/schainpy/controller.py b/schainpy/controller.py index 001abe6..ddfb54e 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -606,6 +606,8 @@ if __name__ == '__main__': # opObj11.addParameter(name='zmin', value='70', format='int') # opObj11.addParameter(name='zmax', value='90', format='int') opObj11.addParameter(name='showprofile', value='0', format='int') + opObj11.addParameter(name='save', value='1', format='int') + opObj11.addParameter(name='filename', value='/Users/dsuarez/Pictures/SpectraPlot.png', format='str') opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') opObj11.addParameter(name='idfigure', value='10', format='int') diff --git a/schainpy/model/graphics/figure.py b/schainpy/model/graphics/figure.py index 2c005f3..9a4488b 100644 --- a/schainpy/model/graphics/figure.py +++ b/schainpy/model/graphics/figure.py @@ -104,6 +104,9 @@ class Figure: axesObj = Axes(self.fig, *args) self.axesObjList.append(axesObj) + def saveFigure(self, *args): + self.__driver.saveFigure(self.fig, *args) + def draw(self): self.__driver.draw(self.fig) @@ -149,6 +152,9 @@ class Axes: self.__driver.setAxesText(self.ax, text) + def setXAxisAsTime(self): + pass + def pline(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index 9d71c3f..c7c896e 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -1,10 +1,14 @@ import numpy +import datetime import matplotlib matplotlib.use("TKAgg") import matplotlib.pyplot +import matplotlib.dates #import scitools.numpyutils from mpl_toolkits.axes_grid1 import make_axes_locatable +from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter + def init(idfigure, wintitle, width, height, facecolor="w"): matplotlib.pyplot.ioff() @@ -109,6 +113,9 @@ def closeFigure(): return +def saveFigure(fig, filename): + fig.savefig(filename) + def setWinTitle(fig, title): fig.canvas.manager.set_window_title(title) @@ -193,7 +200,7 @@ def pline(iplot, x, y, xlabel='', ylabel='', title=''): iplot.set_data(x, y) -def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): +def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel='',XAxisAsTime=False): divider = make_axes_locatable(ax) 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 fig.add_axes(ax_cb) ax.set_xlim([xmin,xmax]) + + if XAxisAsTime: + seconds = numpy.array([xmin, xmax]) + datesList = map(datetime.datetime.fromtimestamp, seconds) + ax.set_xlim([datesList[0],datesList[-1]]) + ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) + ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) + ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) + xdateList = map(datetime.datetime.fromtimestamp, x) + xdate = matplotlib.dates.date2num(xdateList) + x = xdate + + ax.set_ylim([ymin,ymax]) printLabels(ax, xlabel, ylabel, title) @@ -239,8 +259,10 @@ def pcolor(imesh, z, xlabel='', ylabel='', title=''): imesh.set_array(z.ravel()) def addpcolor(ax, x, y, z, zmin, zmax): + xdateList = map(datetime.datetime.fromtimestamp, x) + xdate = matplotlib.dates.date2num(xdateList) - imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) + imesh = ax.pcolormesh(xdate,y,z.T,vmin=zmin,vmax=zmax) def draw(fig): diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index 3a01aff..17ee6d9 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -61,7 +61,7 @@ class RTIPlot(Figure): counter += 1 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', - xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): + xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None): """ @@ -126,7 +126,7 @@ class RTIPlot(Figure): z = avg[i].reshape((1,-1)) axes.pcolor(x, y, z, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, - xlabel=xlabel, ylabel=ylabel, title=title, rti=True, + xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, ticksize=9, cblabel='') if self.__showprofile: @@ -139,6 +139,9 @@ class RTIPlot(Figure): self.draw() + if save: + self.saveFigure(filename) + class SpectraPlot(Figure): __isConfig = None @@ -197,7 +200,7 @@ class SpectraPlot(Figure): counter += 1 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', - xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): + xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None): """ @@ -273,6 +276,9 @@ class SpectraPlot(Figure): grid='x') self.draw() + + if save: + self.saveFigure(filename) class Scope(Figure): @@ -304,7 +310,7 @@ class Scope(Figure): self.nplots = nplots def run(self, dataOut, idfigure, wintitle="", channelList=None, - xmin=None, xmax=None, ymin=None, ymax=None): + xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): """ @@ -360,5 +366,6 @@ class Scope(Figure): self.draw() - + if save: + self.saveFigure(filename) \ No newline at end of file