Example #1
0
    def plotContourFills(self, painter, posn, axes, clip):
        """Plot the traced contours on the painter."""

        s = self.settings

        # don't draw if there are no cached polygons
        if self._cachedpolygons is None or s.Fills.hide:
            return

        # ensure plotting of contours does not go outside the area
        painter.setPen(qt4.QPen(qt4.Qt.NoPen))

        # iterate over each level, and list of lines
        for num, polylist in enumerate(self._cachedpolygons):

            # move to the next line style
            painter.setBrush(s.Fills.get('fills').makeBrush(num))
                
            # iterate over each complete line of the contour
            for poly in polylist:
                # convert coordinates from graph to plotter
                xplt = axes[0].dataToPlotterCoords(posn, poly[:,0])
                yplt = axes[1].dataToPlotterCoords(posn, poly[:,1])

                pts = qt4.QPolygonF()
                utils.addNumpyToPolygonF(pts, xplt, yplt)
                utils.plotClippedPolygon(painter, clip, pts)
Example #2
0
    def _fillRegion(self, painter, pxpts, pypts, bounds, belowleft, clip):
        """Fill the region above/below or left/right of the points.

        belowleft fills below if the variable is 'x', or left if 'y'
        otherwise it fills above/right."""

        # find starting and ending points for the filled region
        x1, y1, x2, y2 = bounds
        s = self.settings
        
        pts = qt4.QPolygonF()
        if self.settings.variable == 'x':
            if belowleft:
                pts.append(qt4.QPointF(pxpts[0], y2))
                endpt = qt4.QPointF(pxpts[-1], y2)
            else:
                pts.append(qt4.QPointF(pxpts[0], y1))
                endpt = qt4.QPointF(pxpts[-1], y1)
        else:
            if belowleft:
                pts.append(qt4.QPointF(x1, pypts[0]))
                endpt = qt4.QPointF(x1, pypts[-1])
            else:
                pts.append(qt4.QPointF(x2, pypts[0]))
                endpt = qt4.QPointF(x2, pypts[-1])

        # add the points between
        utils.addNumpyToPolygonF(pts, pxpts, pypts)

        # stick on the ending point
        pts.append(endpt)

        # actually do the filling
        utils.plotClippedPolygon(painter, clip, pts)
Example #3
0
    def _drawPlotLine(self, painter, xvals, yvals, posn, xdata, ydata, cliprect):
        """Draw the line connecting the points."""

        pts = self._getLinePoints(xvals, yvals, posn, xdata, ydata)
        if len(pts) < 2:
            return
        s = self.settings

        if not s.FillBelow.hide:
            # empty pen (line gets drawn below)
            painter.setPen(qt4.QPen(qt4.Qt.NoPen))
            painter.setBrush(s.FillBelow.makeQBrush())

            # construct polygon to draw filled region
            polypts = qt4.QPolygonF([qt4.QPointF(pts[0].x(), posn[3])])
            polypts += pts
            polypts.append(qt4.QPointF(pts[len(pts) - 1].x(), posn[3]))

            # clip polygon and paint
            utils.plotClippedPolygon(painter, cliprect, polypts)

        if not s.FillAbove.hide:
            painter.setPen(qt4.QPen(qt4.Qt.NoPen))
            painter.setBrush(s.FillAbove.makeQBrush())

            polypts = qt4.QPolygonF([qt4.QPointF(pts[0].x(), posn[1])])
            polypts += pts
            polypts.append(qt4.QPointF(pts[len(pts) - 1].x(), posn[1]))

            utils.plotClippedPolygon(painter, cliprect, polypts)

        # draw line between points
        if not s.PlotLine.hide:
            painter.setPen(s.PlotLine.makeQPen(painter))
            utils.plotClippedPolyline(painter, cliprect, pts)
Example #4
0
    def drawFillPts(self, painter, cliprect, ptsx, ptsy, filltype):
        '''Draw points for plotting a fill.'''
        pts = qt4.QPolygonF()
        utils.addNumpyToPolygonF(pts, ptsx, ptsy)

        # this is broken: FIXME
        if filltype == 'left':
            dyend = ptsy[-1]-self._box[1]
            pts.append( qt4.QPointF(ptsx[-1]-dyend*tan30, self._box[1]) )
            dystart = ptsy[0]-self._box[1]
            pts.append( qt4.QPointF(ptsx[0]-dystart*tan30, self._box[1]) )
        elif filltype == 'right':
            pts.append( qt4.QPointF(self._box[2], ptsy[-1]) )
            pts.append( qt4.QPointF(self._box[2], ptsy[0]) )
        elif filltype == 'bottom':
            dyend = self._box[3]-ptsy[-1]
            pts.append( qt4.QPointF(ptsx[-1]-dyend*tan30, self._box[3]) )
            dystart = self._box[3]-ptsy[0]
            pts.append( qt4.QPointF(ptsx[0]-dystart*tan30, self._box[3]) )
        elif filltype == 'polygon':
            pass
        else:
            pts = None

        if pts is not None:
            utils.plotClippedPolygon(painter, cliprect, pts)
Example #5
0
def _errorBarsDiamond(style, xmin, xmax, ymin, ymax, xplotter, yplotter, s, painter, clip):
    """Draw diamond around error region."""
    if None not in (xmin, xmax, ymin, ymax):
        painter.setBrush(qt4.QBrush())

        for xp, yp, xmn, ymn, xmx, ymx in itertools.izip(xplotter, yplotter, xmin, ymin, xmax, ymax):

            utils.plotClippedPolygon(
                painter,
                clip,
                qt4.QPolygonF([qt4.QPointF(xmn, yp), qt4.QPointF(xp, ymx), qt4.QPointF(xmx, yp), qt4.QPointF(xp, ymn)]),
            )
Example #6
0
    def drawFillPts(self, painter, cliprect, ptsx, ptsy, filltype):
        '''Draw points for plotting a fill.'''
        pts = qt4.QPolygonF()
        utils.addNumpyToPolygonF(pts, ptsx, ptsy)

        if filltype == 'center':
            pts.append( qt4.QPointF(self._xc, self._yc) )
            utils.plotClippedPolygon(painter, cliprect, pts)
        elif filltype == 'outside':
            pp = qt4.QPainterPath()
            pp.moveTo(self._xc, self._yc)
            pp.arcTo(cliprect, 0, 360)
            pp.addPolygon(pts)
            painter.fillPath(pp, painter.brush())
        elif filltype == 'polygon':
            utils.plotClippedPolygon(painter, cliprect, pts)