From 05aa3e93934887da5f5abc9ba6c79619761e47b1 Mon Sep 17 00:00:00 2001 From: 2xB <31772910+2xB@users.noreply.github.com> Date: Sat, 17 Aug 2019 18:57:40 +0200 Subject: [PATCH] Add 'fillOutline' option to draw an outline around a filled area (#999) --- examples/histogram.py | 2 +- pyqtgraph/graphicsItems/PlotCurveItem.py | 9 +++++++-- pyqtgraph/graphicsItems/PlotDataItem.py | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/histogram.py b/examples/histogram.py index a25f0947..85fbe3f0 100644 --- a/examples/histogram.py +++ b/examples/histogram.py @@ -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. ## 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 y = pg.pseudoScatter(vals, spacing=0.15) diff --git a/pyqtgraph/graphicsItems/PlotCurveItem.py b/pyqtgraph/graphicsItems/PlotCurveItem.py index 673d8334..fb3f6ea6 100644 --- a/pyqtgraph/graphicsItems/PlotCurveItem.py +++ b/pyqtgraph/graphicsItems/PlotCurveItem.py @@ -61,6 +61,7 @@ class PlotCurveItem(GraphicsObject): self.opts = { 'shadowPen': None, 'fillLevel': None, + 'fillOutline': False, 'brush': None, 'stepMode': False, 'name': None, @@ -291,7 +292,7 @@ class PlotCurveItem(GraphicsObject): self.fillPath = None self.invalidateBounds() self.update() - + def setData(self, *args, **kargs): """ =============== ======================================================== @@ -305,6 +306,8 @@ class PlotCurveItem(GraphicsObject): :func:`mkPen ` is allowed. fillLevel (float or None) Fill the area 'under' the curve to *fillLevel* + fillOutline (bool) If True, an outline surrounding the *fillLevel* + area is drawn. brush QBrush to use when filling. Any single argument accepted by :func:`mkBrush ` is allowed. antialias (bool) Whether to use antialiasing when drawing. This @@ -394,6 +397,8 @@ class PlotCurveItem(GraphicsObject): self.setShadowPen(kargs['shadowPen']) if 'fillLevel' in kargs: self.setFillLevel(kargs['fillLevel']) + if 'fillOutline' in kargs: + self.opts['fillOutline'] = kargs['fillOutline'] if 'brush' in kargs: self.setBrush(kargs['brush']) if 'antialias' in kargs: @@ -501,7 +506,7 @@ class PlotCurveItem(GraphicsObject): p.setPen(sp) p.drawPath(path) p.setPen(cp) - if self.fillPath is not None: + if self.opts['fillOutline'] and self.fillPath is not None: p.drawPath(self.fillPath) else: p.drawPath(path) diff --git a/pyqtgraph/graphicsItems/PlotDataItem.py b/pyqtgraph/graphicsItems/PlotDataItem.py index bf119879..172e3beb 100644 --- a/pyqtgraph/graphicsItems/PlotDataItem.py +++ b/pyqtgraph/graphicsItems/PlotDataItem.py @@ -67,6 +67,8 @@ class PlotDataItem(GraphicsObject): shadowPen Pen for secondary line to draw behind the primary line. disabled by default. May be any single argument accepted by :func:`mkPen() ` 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. May be any single argument accepted by :func:`mkBrush() ` stepMode If True, two orthogonal lines are drawn for each sample @@ -154,6 +156,7 @@ class PlotDataItem(GraphicsObject): 'pen': (200,200,200), 'shadowPen': None, 'fillLevel': None, + 'fillOutline': False, 'fillBrush': None, 'stepMode': None, @@ -474,7 +477,7 @@ class PlotDataItem(GraphicsObject): def updateItems(self): 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] scatterArgs = {}