File: FillBetweenItem.py

package info (click to toggle)
python-pyqtgraph 0.9.8-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,552 kB
  • ctags: 4,262
  • sloc: python: 30,181; makefile: 116; sh: 1
file content (23 lines) | stat: -rw-r--r-- 797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pyqtgraph as pg

class FillBetweenItem(pg.QtGui.QGraphicsPathItem):
    """
    GraphicsItem filling the space between two PlotDataItems.
    """
    def __init__(self, p1, p2, brush=None):
        pg.QtGui.QGraphicsPathItem.__init__(self)
        self.p1 = p1
        self.p2 = p2
        p1.sigPlotChanged.connect(self.updatePath)
        p2.sigPlotChanged.connect(self.updatePath)
        if brush is not None:
            self.setBrush(pg.mkBrush(brush))
        self.setZValue(min(p1.zValue(), p2.zValue())-1)
        self.updatePath()

    def updatePath(self):
        p1 = self.p1.curve.path
        p2 = self.p2.curve.path
        path = pg.QtGui.QPainterPath()
        path.addPolygon(p1.toSubpathPolygons()[0] + p2.toReversed().toSubpathPolygons()[0])
        self.setPath(path)