Add 'fillOutline' option to draw an outline around a filled area (#999)

This commit is contained in:
2xB 2019-08-17 18:57:40 +02:00 committed by Ogi Moore
parent cd3f7fd68e
commit 05aa3e9393
3 changed files with 12 additions and 4 deletions

View File

@ -22,7 +22,7 @@ y,x = np.histogram(vals, bins=np.linspace(-3, 8, 40))
## Using stepMode=True causes the plot to draw two lines for each sample. ## Using stepMode=True causes the plot to draw two lines for each sample.
## notice that len(x) == len(y)+1 ## notice that len(x) == len(y)+1
plt1.plot(x, y, stepMode=True, fillLevel=0, brush=(0,0,255,150)) plt1.plot(x, y, stepMode=True, fillLevel=0, fillOutline=True, brush=(0,0,255,150))
## Now draw all points as a nicely-spaced scatter plot ## Now draw all points as a nicely-spaced scatter plot
y = pg.pseudoScatter(vals, spacing=0.15) y = pg.pseudoScatter(vals, spacing=0.15)

View File

@ -61,6 +61,7 @@ class PlotCurveItem(GraphicsObject):
self.opts = { self.opts = {
'shadowPen': None, 'shadowPen': None,
'fillLevel': None, 'fillLevel': None,
'fillOutline': False,
'brush': None, 'brush': None,
'stepMode': False, 'stepMode': False,
'name': None, 'name': None,
@ -291,7 +292,7 @@ class PlotCurveItem(GraphicsObject):
self.fillPath = None self.fillPath = None
self.invalidateBounds() self.invalidateBounds()
self.update() self.update()
def setData(self, *args, **kargs): def setData(self, *args, **kargs):
""" """
=============== ======================================================== =============== ========================================================
@ -305,6 +306,8 @@ class PlotCurveItem(GraphicsObject):
:func:`mkPen <pyqtgraph.mkPen>` is allowed. :func:`mkPen <pyqtgraph.mkPen>` is allowed.
fillLevel (float or None) Fill the area 'under' the curve to fillLevel (float or None) Fill the area 'under' the curve to
*fillLevel* *fillLevel*
fillOutline (bool) If True, an outline surrounding the *fillLevel*
area is drawn.
brush QBrush to use when filling. Any single argument accepted brush QBrush to use when filling. Any single argument accepted
by :func:`mkBrush <pyqtgraph.mkBrush>` is allowed. by :func:`mkBrush <pyqtgraph.mkBrush>` is allowed.
antialias (bool) Whether to use antialiasing when drawing. This antialias (bool) Whether to use antialiasing when drawing. This
@ -394,6 +397,8 @@ class PlotCurveItem(GraphicsObject):
self.setShadowPen(kargs['shadowPen']) self.setShadowPen(kargs['shadowPen'])
if 'fillLevel' in kargs: if 'fillLevel' in kargs:
self.setFillLevel(kargs['fillLevel']) self.setFillLevel(kargs['fillLevel'])
if 'fillOutline' in kargs:
self.opts['fillOutline'] = kargs['fillOutline']
if 'brush' in kargs: if 'brush' in kargs:
self.setBrush(kargs['brush']) self.setBrush(kargs['brush'])
if 'antialias' in kargs: if 'antialias' in kargs:
@ -501,7 +506,7 @@ class PlotCurveItem(GraphicsObject):
p.setPen(sp) p.setPen(sp)
p.drawPath(path) p.drawPath(path)
p.setPen(cp) p.setPen(cp)
if self.fillPath is not None: if self.opts['fillOutline'] and self.fillPath is not None:
p.drawPath(self.fillPath) p.drawPath(self.fillPath)
else: else:
p.drawPath(path) p.drawPath(path)

View File

@ -67,6 +67,8 @@ class PlotDataItem(GraphicsObject):
shadowPen Pen for secondary line to draw behind the primary line. disabled by default. shadowPen Pen for secondary line to draw behind the primary line. disabled by default.
May be any single argument accepted by :func:`mkPen() <pyqtgraph.mkPen>` May be any single argument accepted by :func:`mkPen() <pyqtgraph.mkPen>`
fillLevel Fill the area between the curve and fillLevel fillLevel Fill the area between the curve and fillLevel
fillOutline (bool) If True, an outline surrounding the *fillLevel*
area is drawn.
fillBrush Fill to use when fillLevel is specified. fillBrush Fill to use when fillLevel is specified.
May be any single argument accepted by :func:`mkBrush() <pyqtgraph.mkBrush>` May be any single argument accepted by :func:`mkBrush() <pyqtgraph.mkBrush>`
stepMode If True, two orthogonal lines are drawn for each sample stepMode If True, two orthogonal lines are drawn for each sample
@ -154,6 +156,7 @@ class PlotDataItem(GraphicsObject):
'pen': (200,200,200), 'pen': (200,200,200),
'shadowPen': None, 'shadowPen': None,
'fillLevel': None, 'fillLevel': None,
'fillOutline': False,
'fillBrush': None, 'fillBrush': None,
'stepMode': None, 'stepMode': None,
@ -474,7 +477,7 @@ class PlotDataItem(GraphicsObject):
def updateItems(self): def updateItems(self):
curveArgs = {} curveArgs = {}
for k,v in [('pen','pen'), ('shadowPen','shadowPen'), ('fillLevel','fillLevel'), ('fillBrush', 'brush'), ('antialias', 'antialias'), ('connect', 'connect'), ('stepMode', 'stepMode')]: for k,v in [('pen','pen'), ('shadowPen','shadowPen'), ('fillLevel','fillLevel'), ('fillOutline', 'fillOutline'), ('fillBrush', 'brush'), ('antialias', 'antialias'), ('connect', 'connect'), ('stepMode', 'stepMode')]:
curveArgs[v] = self.opts[k] curveArgs[v] = self.opts[k]
scatterArgs = {} scatterArgs = {}