schainPlotLib.py
153 lines
| 4.5 KiB
| text/x-python
|
PythonLexer
|
r133 | import plplot | ||
import numpy | ||||
import sys | ||||
import plplot #condicional | ||||
class Driver: | ||||
|
r135 | def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colorbar, colormap): | ||
|
r133 | if driver == "plplot": | ||
|
r135 | self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colorbar, colormap) | ||
|
r133 | elif driver == "mpl": | ||
|
r135 | self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap) | ||
|
r133 | else: | ||
raise ValueError, "The driver: %s is not defined"%driver | ||||
class PlplotDriver: | ||||
__isDriverOpen = False | ||||
pldriver = None | ||||
|
r135 | def __init__(self, idfigure, xw, yw, wintitle, overplot, colorbar, colormap): | ||
|
r133 | |||
if idfigure == None: | ||||
raise ValueError, 'idfigure input must be defined' | ||||
self.idfigure = idfigure | ||||
self.xw = xw | ||||
self.yw = yw | ||||
self.wintitle = wintitle | ||||
self.overplot = overplot | ||||
|
r135 | self.colorbar = colorbar | ||
|
r133 | self.colormap = colormap | ||
|
r135 | |||
|
r133 | |||
|
r135 | def setFigure(self): | ||
|
r133 | """ | ||
previous configuration to open(init) the plplot driver | ||||
""" | ||||
plplot.plsstrm(self.idfigure) | ||||
plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL) | ||||
plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw)) | ||||
|
r134 | |||
|
r133 | |||
def openDriver(self, pldriver=None): | ||||
if pldriver == None: | ||||
if sys.platform == "linux": | ||||
pldriver = "xcairo" | ||||
|
r134 | |||
if sys.platform == "linux2": | ||||
pldriver = "xcairo" | ||||
|
r133 | elif sys.platform == "darwin": | ||
pldriver = "xwin" | ||||
else: | ||||
pldriver = "" | ||||
|
r134 | plplot.plsdev("xwin") #para pruebas | ||
plplot.plscolbg(255,255,255) | ||||
plplot.plscol0(1,0,0,0) | ||||
|
r133 | plplot.plinit() | ||
plplot.plspause(False) | ||||
self.pldriver = pldriver | ||||
def closeDriver(self): | ||||
pass | ||||
def openPage(self): | ||||
plplot.plbop() | ||||
plplot.pladv(0) | ||||
def closePage(self): | ||||
plplot.pleop() | ||||
def openFigure(self): | ||||
plplot.plbop() | ||||
plplot.pladv(0) | ||||
def closeFigure(self): | ||||
plplot.pleop() | ||||
def setSubPlots(self,nrows, ncolumns): | ||||
|
r135 | plplot.plssub(ncolumns,nrows) | ||
|
r133 | |||
|
r135 | def setPlotLabels(self, xlabel, ylabel, title): | ||
plplot.pllab(xlabel, ylabel, title) | ||||
|
r133 | |||
|
r135 | def setFigTitle(self, title,color="black", szchar=0.55): | ||
self.setSubPlots(1, 0) | ||||
plplot.pladv(0) | ||||
plplot.plvpor(0., 1., 0., 1.) | ||||
|
r133 | |||
|
r135 | if color == "black": | ||
plplot.plcol0(1) | ||||
if color == "white": | ||||
plplot.plcol0(15) | ||||
|
r133 | |||
|
r135 | plplot.plschr(0.0,szchar) | ||
plplot.plmtex("t",-1., 0.5, 0.5, title) | ||||
def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"): | ||||
""" | ||||
xopt, yopt: entradas que no se aplican en MPL | ||||
""" | ||||
plplot.pladv(id) | ||||
plplot.plschr(0.0,szchar-0.05) | ||||
plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | ||||
plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax)) | ||||
if xaxisastime: | ||||
plplot.pltimefmt(timefmt) | ||||
timedelta = (xmax - xmin + 1)/8. | ||||
plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0) | ||||
else: | ||||
plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) | ||||
|
r133 | |||
|
r135 | def refresh(self): | ||
plplot.plflush() | ||||
|
r133 | |||
|
r135 | def basicLine(self, x, y, xmin, xmax, ymin, ymax, color, id, xpos, ypos): | ||
|
r133 | |||
|
r135 | """ | ||
Inputs: | ||||
x: datos en el eje x | ||||
|
r133 | |||
|
r135 | y: datos en el eje y | ||
|
r133 | |||
|
r135 | xmin, xmax: intervalo de datos en el eje x | ||
|
r133 | |||
|
r135 | ymin, ymax: intervalo de datos en el eje y | ||
|
r133 | |||
|
r135 | color: color de la linea a dibujarse | ||
|
r133 | |||
|
r135 | id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada | ||
plot esta definido por xpos, ypos. | ||||
|
r133 | |||
|
r135 | xpos,ypos: coordenadas que indican la posicion del plot en el frame | ||
|
r133 | |||
|
r135 | """ | ||
|
r133 | |||
|
r135 | plplot.pladv(id) | ||
plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1]) | ||||
plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax)) | ||||
|
r133 | |||
|
r135 | if color == "blue": | ||
colline = 9 | ||||
if color == "green": | ||||
colline = 3 | ||||
plplot.plcol0(colline) | ||||
plplot.plline(x, y) | ||||
|
r133 | plplot.plcol0(1) | ||
|
r135 | plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0) | ||