From d55526a787f9a841952540dec7b1e46328ad1998 Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Mon, 23 Apr 2012 14:57:49 -0400 Subject: [PATCH] Corrected handling of positional arguments in PlotCurveItem.__init__ --- graphicsItems/PlotCurveItem.py | 108 ++++++++++----------------------- 1 file changed, 33 insertions(+), 75 deletions(-) diff --git a/graphicsItems/PlotCurveItem.py b/graphicsItems/PlotCurveItem.py index b9e4042f..8840e339 100644 --- a/graphicsItems/PlotCurveItem.py +++ b/graphicsItems/PlotCurveItem.py @@ -34,59 +34,39 @@ class PlotCurveItem(GraphicsObject): sigPlotChanged = QtCore.Signal(object) sigClicked = QtCore.Signal(object) - def __init__(self, x=None, y=None, fillLevel=None, copy=False, pen=None, shadowPen=None, brush=None, parent=None, clickable=False): + def __init__(self, *args, **kargs): """ + Forwards all arguments to :func:`setData `. + + Some extra arguments are accepted as well: + ============== ======================================================= **Arguments:** - x, y (numpy arrays) Data to show - pen Pen to use when drawing. Any single argument accepted by - :func:`mkPen ` is allowed. - shadowPen Pen for drawing behind the primary pen. Usually this - is used to emphasize the curve by providing a - high-contrast border. Any single argument accepted by - :func:`mkPen ` is allowed. - fillLevel (float or None) Fill the area 'under' the curve to - *fillLevel* - brush QBrush to use when filling. Any single argument accepted - by :func:`mkBrush ` is allowed. + parent The parent GraphicsObject (optional) clickable If True, the item will emit sigClicked when it is - clicked on. + clicked on. Defaults to False. ============== ======================================================= - - - """ - GraphicsObject.__init__(self, parent) + GraphicsObject.__init__(self, kargs.get('parent', None)) self.clear() self.path = None self.fillPath = None self.exportOpts = False self.antialias = False - if y is not None: - self.updateData(y, x) ## this is disastrous for performance. #self.setCacheMode(QtGui.QGraphicsItem.DeviceCoordinateCache) self.metaData = {} self.opts = { - #'spectrumMode': False, - #'logMode': [False, False], - #'downsample': False, - #'alphaHint': 1.0, - #'alphaMode': False, - 'pen': 'w', + 'pen': fn.mkPen('w'), 'shadowPen': None, - 'fillLevel': fillLevel, - 'brush': brush, + 'fillLevel': None, + 'brush': None, } - self.setPen(pen) - self.setShadowPen(shadowPen) - self.setFillLevel(fillLevel) - self.setBrush(brush) - self.setClickable(clickable) - #self.fps = None + self.setClickable(kargs.get('clickable', False)) + self.setData(*args, **kargs) def implements(self, interface=None): ints = ['plotData'] @@ -101,41 +81,6 @@ class PlotCurveItem(GraphicsObject): def getData(self): return self.xData, self.yData - #if self.xData is None: - #return (None, None) - #if self.xDisp is None: - #nanMask = np.isnan(self.xData) | np.isnan(self.yData) - #if any(nanMask): - #x = self.xData[~nanMask] - #y = self.yData[~nanMask] - #else: - #x = self.xData - #y = self.yData - #ds = self.opts['downsample'] - #if ds > 1: - #x = x[::ds] - ##y = resample(y[:len(x)*ds], len(x)) ## scipy.signal.resample causes nasty ringing - #y = y[::ds] - #if self.opts['spectrumMode']: - #f = fft(y) / len(y) - #y = abs(f[1:len(f)/2]) - #dt = x[-1] - x[0] - #x = np.linspace(0, 0.5*len(x)/dt, len(y)) - #if self.opts['logMode'][0]: - #x = np.log10(x) - #if self.opts['logMode'][1]: - #y = np.log10(y) - #self.xDisp = x - #self.yDisp = y - ##print self.yDisp.shape, self.yDisp.min(), self.yDisp.max() - ##print self.xDisp.shape, self.xDisp.min(), self.xDisp.max() - #return self.xDisp, self.yDisp - - #def generateSpecData(self): - #f = fft(self.yData) / len(self.yData) - #self.ySpec = abs(f[1:len(f)/2]) - #dt = self.xData[-1] - self.xData[0] - #self.xSpec = linspace(0, 0.5*len(self.xData)/dt, len(self.ySpec)) def dataBounds(self, ax, frac=1.0): (x, y) = self.getData() @@ -154,12 +99,6 @@ class PlotCurveItem(GraphicsObject): else: return (scipy.stats.scoreatpercentile(d, 50 - (frac * 50)), scipy.stats.scoreatpercentile(d, 50 + (frac * 50))) - #def setMeta(self, data): - #self.metaData = data - - #def meta(self): - #return self.metaData - def setPen(self, *args, **kargs): """Set the pen used to draw the curve.""" self.opts['pen'] = fn.mkPen(*args, **kargs) @@ -219,7 +158,26 @@ class PlotCurveItem(GraphicsObject): def setData(self, *args, **kargs): """ - Accepts most of the same arguments as __init__. + ============== ======================================================= + **Arguments:** + x, y (numpy arrays) Data to show + pen Pen to use when drawing. Any single argument accepted by + :func:`mkPen ` is allowed. + shadowPen Pen for drawing behind the primary pen. Usually this + is used to emphasize the curve by providing a + high-contrast border. Any single argument accepted by + :func:`mkPen ` is allowed. + fillLevel (float or None) Fill the area 'under' the curve to + *fillLevel* + brush QBrush to use when filling. Any single argument accepted + by :func:`mkBrush ` is allowed. + ============== ======================================================= + + If non-keyword arguments are used, they will be interpreted as + setData(y) for a single argument and setData(x, y) for two + arguments. + + """ self.updateData(*args, **kargs)