Пример #1
0
    def plotBox(self, painter, axes, boxposn, posn, width, clip, stats):
        """Draw box for dataset."""

        s = self.settings
        horz = s.direction == "horizontal"

        # convert quartiles, top and bottom whiskers to plotter
        medplt, botplt, topplt, botwhisplt, topwhisplt = tuple(
            axes[not horz].dataToPlotterCoords(
                posn, N.array([stats.median, stats.botquart, stats.topquart, stats.botwhisker, stats.topwhisker])
            )
        )

        # draw whisker top to bottom
        p = s.Whisker.makeQPenWHide(painter)
        p.setCapStyle(qt4.Qt.FlatCap)
        painter.setPen(p)
        swapline(painter, boxposn, topwhisplt, boxposn, botwhisplt, horz)
        # draw ends of whiskers
        endsize = width / 2
        swapline(painter, boxposn - endsize / 2, topwhisplt, boxposn + endsize / 2, topwhisplt, horz)
        swapline(painter, boxposn - endsize / 2, botwhisplt, boxposn + endsize / 2, botwhisplt, horz)

        # draw box fill
        painter.setPen(qt4.QPen(qt4.Qt.NoPen))
        painter.setBrush(s.Fill.makeQBrushWHide())
        swapbox(painter, boxposn - width / 2, botplt, boxposn + width / 2, topplt, horz)

        # draw line across box
        p = s.Whisker.makeQPenWHide(painter)
        p.setCapStyle(qt4.Qt.FlatCap)
        painter.setPen(p)
        swapline(painter, boxposn - width / 2, medplt, boxposn + width / 2, medplt, horz)

        # draw box
        painter.setPen(s.Border.makeQPenWHide(painter))
        painter.setBrush(qt4.QBrush())
        swapbox(painter, boxposn - width / 2, botplt, boxposn + width / 2, topplt, horz)

        # draw outliers
        painter.setPen(s.MarkersLine.makeQPenWHide(painter))
        painter.setBrush(s.MarkersFill.makeQBrushWHide())
        markersize = s.get("markerSize").convert(painter)
        if stats.outliers.shape[0] != 0:
            pltvals = axes[not horz].dataToPlotterCoords(posn, stats.outliers)
            otherpos = N.zeros(pltvals.shape) + boxposn
            if horz:
                x, y = pltvals, otherpos
            else:
                x, y = otherpos, pltvals

            utils.plotMarkers(painter, x, y, s.outliersmarker, markersize, clip=clip)

        # draw mean
        meanplt = axes[not horz].dataToPlotterCoords(posn, N.array([stats.mean]))[0]
        if horz:
            x, y = meanplt, boxposn
        else:
            x, y = boxposn, meanplt
        utils.plotMarker(painter, x, y, s.meanmarker, markersize)
Пример #2
0
    def drawKeySymbol(self, number, painter, x, y, width, height):
        """Draw the plot symbol and/or line."""
        painter.save()
        cliprect = qt4.QRectF(qt4.QPointF(x, y),
                              qt4.QPointF(x + width, y + height))
        painter.setClipRect(cliprect)

        # draw sample error bar
        s = self.settings
        size = s.get('markerSize').convert(painter)
        style = s.errorStyle

        # make some fake error bar data to plot
        xv = s.get('xData').getData(self.document)
        yv = s.get('yData').getData(self.document)
        yp = y + height / 2
        xpts = N.array([x - width, x + width / 2, x + 2 * width])
        ypts = N.array([yp, yp, yp])

        # size of error bars in key
        errorsize = height * 0.4

        # make points for error bars (if any)
        if xv and xv.hasErrors():
            xneg = N.array(
                [x - width, x + width / 2 - errorsize, x + 2 * width])
            xpos = N.array(
                [x - width, x + width / 2 + errorsize, x + 2 * width])
        else:
            xneg = xpos = xpts
        if yv and yv.hasErrors():
            yneg = N.array([yp - errorsize, yp - errorsize, yp - errorsize])
            ypos = N.array([yp + errorsize, yp + errorsize, yp + errorsize])
        else:
            yneg = ypos = ypts

        # plot error bar
        painter.setPen(s.ErrorBarLine.makeQPenWHide(painter))
        for function in _errorBarFunctionMap[style]:
            function(style, xneg, xpos, yneg, ypos, xpts, ypts, s, painter,
                     cliprect)

        # draw line
        if not s.PlotLine.hide:
            painter.setPen(s.PlotLine.makeQPen(painter))
            painter.drawLine(qt4.QPointF(x, yp), qt4.QPointF(x + width, yp))

        # draw marker
        if not s.MarkerLine.hide or not s.MarkerFill.hide:
            if not s.MarkerFill.hide:
                painter.setBrush(s.MarkerFill.makeQBrush())

            if not s.MarkerLine.hide:
                painter.setPen(s.MarkerLine.makeQPen(painter))
            else:
                painter.setPen(qt4.QPen(qt4.Qt.NoPen))

            utils.plotMarker(painter, x + width / 2, yp, s.marker, size)

        painter.restore()
Пример #3
0
    def drawKeySymbol(self, number, painter, x, y, width, height):
        """Draw the plot symbol and/or line."""
        painter.save()
        cliprect = qt4.QRectF(qt4.QPointF(x,y), qt4.QPointF(x+width,y+height))
        painter.setClipRect(cliprect)

        # draw sample error bar
        s = self.settings
        size = s.get('markerSize').convert(painter)
        style = s.errorStyle

        # make some fake error bar data to plot
        xv = s.get('xData').getData(self.document)
        yv = s.get('yData').getData(self.document)
        yp = y + height/2
        xpts = N.array([x-width, x+width/2, x+2*width])
        ypts = N.array([yp, yp, yp])

        # size of error bars in key
        errorsize = height*0.4

        # make points for error bars (if any)
        if xv and xv.hasErrors():
            xneg = N.array([x-width, x+width/2-errorsize, x+2*width])
            xpos = N.array([x-width, x+width/2+errorsize, x+2*width])
        else:
            xneg = xpos = xpts
        if yv and yv.hasErrors():
            yneg = N.array([yp-errorsize, yp-errorsize, yp-errorsize])
            ypos = N.array([yp+errorsize, yp+errorsize, yp+errorsize])
        else:
            yneg = ypos = ypts

        # plot error bar
        painter.setPen( s.ErrorBarLine.makeQPenWHide(painter) )
        for function in _errorBarFunctionMap[style]:
            function(style, xneg, xpos, yneg, ypos, xpts, ypts, s,
                     painter, cliprect)

        # draw line
        if not s.PlotLine.hide:
            painter.setPen( s.PlotLine.makeQPen(painter) )
            painter.drawLine( qt4.QPointF(x, yp), qt4.QPointF(x+width, yp) )

        # draw marker
        if not s.MarkerLine.hide or not s.MarkerFill.hide:
            if not s.MarkerFill.hide:
                painter.setBrush( s.MarkerFill.makeQBrush() )

            if not s.MarkerLine.hide:
                painter.setPen( s.MarkerLine.makeQPen(painter) )
            else:
                painter.setPen( qt4.QPen( qt4.Qt.NoPen ) )
                
            utils.plotMarker(painter, x+width/2, yp, s.marker, size)

        painter.restore()
Пример #4
0
    def plotBox(self, painter, axes, boxposn, posn, width, clip, stats):
        """Draw box for dataset."""

        if not N.isfinite(stats.median):
            # skip bad datapoints
            return

        s = self.settings
        horz = (s.direction == 'horizontal')

        # convert quartiles, top and bottom whiskers to plotter
        medplt, botplt, topplt, botwhisplt, topwhisplt = tuple(
            axes[not horz].dataToPlotterCoords(
                posn,
                N.array([
                    stats.median, stats.botquart, stats.topquart,
                    stats.botwhisker, stats.topwhisker
                ])))

        # draw whisker top to bottom
        p = s.Whisker.makeQPenWHide(painter)
        p.setCapStyle(qt4.Qt.FlatCap)
        painter.setPen(p)
        swapline(painter, boxposn, topwhisplt, boxposn, botwhisplt, horz)
        # draw ends of whiskers
        endsize = width / 2
        swapline(painter, boxposn - endsize / 2, topwhisplt,
                 boxposn + endsize / 2, topwhisplt, horz)
        swapline(painter, boxposn - endsize / 2, botwhisplt,
                 boxposn + endsize / 2, botwhisplt, horz)

        # draw box fill
        boxpath = qt4.QPainterPath()
        boxpath.addRect(
            swapbox(painter, boxposn - width / 2, botplt, boxposn + width / 2,
                    topplt, horz))
        utils.brushExtFillPath(painter, s.Fill, boxpath)

        # draw line across box
        p = s.Whisker.makeQPenWHide(painter)
        p.setCapStyle(qt4.Qt.FlatCap)
        painter.setPen(p)
        swapline(painter, boxposn - width / 2, medplt, boxposn + width / 2,
                 medplt, horz)

        # draw box
        painter.strokePath(boxpath, s.Border.makeQPenWHide(painter))

        # draw outliers
        painter.setPen(s.MarkersLine.makeQPenWHide(painter))
        painter.setBrush(s.MarkersFill.makeQBrushWHide())
        markersize = s.get('markerSize').convert(painter)
        if stats.outliers.shape[0] != 0:
            pltvals = axes[not horz].dataToPlotterCoords(posn, stats.outliers)
            otherpos = N.zeros(pltvals.shape) + boxposn
            if horz:
                x, y = pltvals, otherpos
            else:
                x, y = otherpos, pltvals

            utils.plotMarkers(painter,
                              x,
                              y,
                              s.outliersmarker,
                              markersize,
                              clip=clip)

        # draw mean
        meanplt = axes[not horz].dataToPlotterCoords(posn,
                                                     N.array([stats.mean]))[0]
        if horz:
            x, y = meanplt, boxposn
        else:
            x, y = boxposn, meanplt
        utils.plotMarker(painter, x, y, s.meanmarker, markersize)