Corrected handling of positional arguments in PlotCurveItem.__init__

This commit is contained in:
Luke Campagnola 2012-04-23 14:57:49 -04:00
parent 2149f9db29
commit d55526a787

View File

@ -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 <pyqtgraph.PlotCurveItem.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 <pyqtgraph.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 <pyqtgraph.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 <pyqtgraph.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 <pyqtgraph.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 <pyqtgraph.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 <pyqtgraph.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)