def _plotContours(self, painter, posn, axes, linestyles, contours, showlabels, hidelines, clip): """Plot a set of contours. """ s = self.settings # no lines cached as no line styles if contours is None: return # iterate over each level, and list of lines for num, linelist in enumerate(contours): # move to the next line style painter.setPen(linestyles.makePen(painter, num)) # iterate over each complete line of the contour for curve in linelist: # convert coordinates from graph to plotter xplt = axes[0].dataToPlotterCoords(posn, curve[:,0]) yplt = axes[1].dataToPlotterCoords(posn, curve[:,1]) pts = qt4.QPolygonF() utils.addNumpyToPolygonF(pts, xplt, yplt) if showlabels: self.plotContourLabel(painter, s.levelsOut[num], xplt, yplt, not hidelines) else: # actually draw the curve to the plotter if not hidelines: utils.plotClippedPolyline(painter, clip, pts)
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 for fill in (s.FillBelow, s.FillAbove): if not fill.hide: polypts = qt4.QPolygonF([{ 'bottom': qt4.QPointF(pts[0].x(), posn[3]), 'top': qt4.QPointF(pts[0].x(), posn[1]), 'left': qt4.QPointF(posn[0], pts[0].y()), 'right': qt4.QPointF(posn[2], pts[0].y()), }[fill.edge]]) polypts += pts polypts.append({ 'bottom': qt4.QPointF(pts[-1].x(), posn[3]), 'top': qt4.QPointF(pts[-1].x(), posn[1]), 'left': qt4.QPointF(posn[0], pts[-1].y()), 'right': qt4.QPointF(posn[2], pts[-1].y()), }[fill.edge]) utils.brushExtFillPolygon(painter, fill, cliprect, polypts) # draw line between points if not s.PlotLine.hide: painter.setPen( s.PlotLine.makeQPen(painter) ) utils.plotClippedPolyline(painter, cliprect, pts)
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)
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: # 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])) utils.brushExtFillPolygon(painter, s.FillBelow, cliprect, polypts) if not s.FillAbove.hide: polypts = qt4.QPolygonF([qt4.QPointF(pts[0].x(), posn[1])]) polypts += pts polypts.append(qt4.QPointF(pts[len(pts) - 1].x(), posn[1])) utils.brushExtFillPolygon(painter, s.FillAbove, cliprect, polypts) # draw line between points if not s.PlotLine.hide: painter.setPen(s.PlotLine.makeQPen(painter)) utils.plotClippedPolyline(painter, cliprect, pts)
def _errorBarsFilled(style, xmin, xmax, ymin, ymax, xplotter, yplotter, s, painter, clip): """Draw filled region as error region.""" ptsabove = qt4.QPolygonF() ptsbelow = qt4.QPolygonF() for orientation, edges, plotpts, minpts, maxpts, hideline in ( ('vert', ('top', 'bottom'), xplotter, ymin, ymax, s.ErrorBarLine.hideVert), ('horz', ('left', 'right'), yplotter, xmin, xmax, s.ErrorBarLine.hideHorz) ): if ( (orientation in style) and not hideline and (minpts is not None) and (maxpts is not None) ): utils.addNumpyToPolygonF(ptsbelow, plotpts, minpts) utils.addNumpyToPolygonF(ptsabove, plotpts, maxpts) if 'fill' in style: retnpts = qt4.QPolygonF() fillpts = { 'top': ptsabove, 'left': ptsabove, 'bottom': ptsbelow, 'right': ptsbelow } utils.addNumpyToPolygonF(retnpts, xplotter[::-1], yplotter[::-1]) # See note in addSettings about names of FillAbove and # FillBelow for fill in (s.FillAbove, s.FillBelow): # polygons consist of lines joining the points and # continuing back along the plot line (retnpts) if not fill.hideerror: utils.brushExtFillPolygon(painter, fill, clip, fillpts[fill.edge]+retnpts, ignorehide=True) utils.plotClippedPolyline(painter, clip, ptsabove) utils.plotClippedPolyline(painter, clip, ptsbelow)
def draw(self, parentposn, phelper, outerbounds=None): '''Plot the data on a plotter.''' posn = Widget.draw(self, parentposn, phelper, outerbounds=outerbounds) s = self.settings d = self.document # exit if hidden if s.hide: return d1 = s.get('data1').getData(d) d2 = s.get('data2').getData(d) dscale = s.get('scalePoints').getData(d) text = s.get('labels').getData(d, checknull=True) if not d1 or not d2: return x1, y1, x2, y2 = posn cliprect = qt4.QRectF( qt4.QPointF(x1, y1), qt4.QPointF(x2, y2) ) painter = phelper.painter(self, posn) self.parent.setClip(painter, posn) # split parts separated by NaNs for v1, v2, scalings, textitems in document.generateValidDatasetParts( d1, d2, dscale, text): # convert data (chopping down length) v1d, v2d = v1.data, v2.data minlen = min(v1d.shape[0], v2d.shape[0]) v1d, v2d = v1d[:minlen], v2d[:minlen] px, py = self.parent.graphToPlotCoords(v1d, v2d) # do fill1 (if any) if not s.Fill1.hide: self.parent.drawFillPts(painter, s.Fill1, cliprect, px, py) # do fill2 if not s.Fill2.hide: self.parent.drawFillPts(painter, s.Fill2, cliprect, px, py) # plot line if not s.PlotLine.hide: painter.setBrush( qt4.QBrush() ) painter.setPen(s.PlotLine.makeQPen(painter)) pts = qt4.QPolygonF() utils.addNumpyToPolygonF(pts, px, py) utils.plotClippedPolyline(painter, cliprect, pts) # markers markersize = s.get('markerSize').convert(painter) pscale = None if scalings: pscale = scalings.data self.plotMarkers(painter, px, py, pscale, markersize, cliprect) # finally plot any labels if textitems and not s.Label.hide: self.drawLabels(painter, px, py, textitems, markersize)
def areaDrawStacked(self, painter, posns, maxwidth, dsvals, axes, widgetposn, clip): """Draw a stacked area plot""" s = self.settings # get axis which values are plotted along ishorz = s.direction == 'horizontal' vaxis = axes[not ishorz] # compute stacked coordinates stackedvals, stackedcoords = self.calcStackedPoints( dsvals, vaxis, widgetposn) # coordinates of origin zerocoords = vaxis.dataToPlotterCoords(widgetposn, N.zeros(posns.shape)) # draw areas (reverse order, so edges are plotted correctly) for dsnum, coords in izip( xrange(len(stackedcoords)-1, -1, -1), stackedcoords[::-1]): # add points at end to make polygon p1 = N.hstack( [ [zerocoords[0]], coords, [zerocoords[-1]] ] ) p2 = N.hstack( [ [posns[0]], posns, [posns[-1]] ] ) # construct polygon on path, clipped poly = qt4.QPolygonF() if ishorz: utils.addNumpyToPolygonF(poly, p1, p2) else: utils.addNumpyToPolygonF(poly, p2, p1) clippoly = qt4.QPolygonF() utils.polygonClip(poly, clip, clippoly) path = qt4.QPainterPath() path.addPolygon(clippoly) path.closeSubpath() # actually draw polygon brush = s.BarFill.get('fills').returnBrushExtended(dsnum) utils.brushExtFillPath(painter, brush, path) # now draw lines poly = qt4.QPolygonF() if ishorz: utils.addNumpyToPolygonF(poly, coords, posns) else: utils.addNumpyToPolygonF(poly, posns, coords) pen = s.BarLine.get('lines').makePen(painter, dsnum) painter.setPen(pen) utils.plotClippedPolyline(painter, clip, poly) # draw error bars barwidth = maxwidth * s.barfill for barval, dsval in izip(stackedvals, dsvals): self.drawErrorBars(painter, posns, barwidth, barval, dsval, axes, widgetposn)
def areaDrawStacked(self, painter, posns, maxwidth, dsvals, axes, widgetposn, clip): """Draw a stacked area plot""" s = self.settings # get axis which values are plotted along ishorz = s.direction == 'horizontal' vaxis = axes[not ishorz] # compute stacked coordinates stackedvals, stackedcoords = self.calcStackedPoints( dsvals, vaxis, widgetposn) # coordinates of origin zerocoords = vaxis.dataToPlotterCoords(widgetposn, N.zeros(posns.shape)) # draw areas (reverse order, so edges are plotted correctly) for dsnum, coords in izip(xrange(len(stackedcoords) - 1, -1, -1), stackedcoords[::-1]): # add points at end to make polygon p1 = N.hstack([[zerocoords[0]], coords, [zerocoords[-1]]]) p2 = N.hstack([[posns[0]], posns, [posns[-1]]]) # construct polygon on path, clipped poly = qt4.QPolygonF() if ishorz: utils.addNumpyToPolygonF(poly, p1, p2) else: utils.addNumpyToPolygonF(poly, p2, p1) clippoly = qt4.QPolygonF() utils.polygonClip(poly, clip, clippoly) path = qt4.QPainterPath() path.addPolygon(clippoly) path.closeSubpath() # actually draw polygon brush = s.BarFill.get('fills').returnBrushExtended(dsnum) utils.brushExtFillPath(painter, brush, path) # now draw lines poly = qt4.QPolygonF() if ishorz: utils.addNumpyToPolygonF(poly, coords, posns) else: utils.addNumpyToPolygonF(poly, posns, coords) pen = s.BarLine.get('lines').makePen(painter, dsnum) painter.setPen(pen) utils.plotClippedPolyline(painter, clip, poly) # draw error bars barwidth = maxwidth * s.barfill for barval, dsval in izip(stackedvals, dsvals): self.drawErrorBars(painter, posns, barwidth, barval, dsval, axes, widgetposn)
def _errorBarsFilled(style, xmin, xmax, ymin, ymax, xplotter, yplotter, s, painter, clip): """Draw filled region as error region.""" ptsabove = qt4.QPolygonF() ptsbelow = qt4.QPolygonF() hidevert = True # keep track of what's shown hidehorz = True if ('vert' in style and (ymin is not None and ymax is not None) and not s.ErrorBarLine.hideVert): hidevert = False # lines above/below points utils.addNumpyToPolygonF(ptsbelow, xplotter, ymin) utils.addNumpyToPolygonF(ptsabove, xplotter, ymax) elif ('horz' in style and (xmin is not None and xmax is not None) and not s.ErrorBarLine.hideHorz): hidehorz = False # lines left/right points utils.addNumpyToPolygonF(ptsbelow, xmin, yplotter) utils.addNumpyToPolygonF(ptsabove, xmax, yplotter) # draw filled regions above/left and below/right if 'fill' in style and not (hidehorz and hidevert): # construct points for error bar regions retnpts = qt4.QPolygonF() utils.addNumpyToPolygonF(retnpts, xplotter[::-1], yplotter[::-1]) # polygons consist of lines joining the points and continuing # back along the plot line (retnpts) if not s.FillBelow.hideerror: utils.brushExtFillPolygon(painter, s.FillBelow, clip, ptsbelow + retnpts, ignorehide=True) if not s.FillAbove.hideerror: utils.brushExtFillPolygon(painter, s.FillAbove, clip, ptsabove + retnpts, ignorehide=True) # draw optional line (on top of fill) utils.plotClippedPolyline(painter, clip, ptsabove) utils.plotClippedPolyline(painter, clip, ptsbelow)
def _errorBarsFilled(style, xmin, xmax, ymin, ymax, xplotter, yplotter, s, painter, clip): """Draw filled region as error region.""" ptsabove = qt4.QPolygonF() ptsbelow = qt4.QPolygonF() hidevert = True # keep track of what's shown hidehorz = True if ( 'vert' in style and (ymin is not None and ymax is not None) and not s.ErrorBarLine.hideVert ): hidevert = False # lines above/below points utils.addNumpyToPolygonF(ptsbelow, xplotter, ymin) utils.addNumpyToPolygonF(ptsabove, xplotter, ymax) elif ( 'horz' in style and (xmin is not None and xmax is not None) and not s.ErrorBarLine.hideHorz ): hidehorz = False # lines left/right points utils.addNumpyToPolygonF(ptsbelow, xmin, yplotter) utils.addNumpyToPolygonF(ptsabove, xmax, yplotter) # draw filled regions above/left and below/right if 'fill' in style and not (hidehorz and hidevert): # construct points for error bar regions retnpts = qt4.QPolygonF() utils.addNumpyToPolygonF(retnpts, xplotter[::-1], yplotter[::-1]) # polygons consist of lines joining the points and continuing # back along the plot line (retnpts) if not s.FillBelow.hideerror: utils.brushExtFillPolygon(painter, s.FillBelow, clip, ptsbelow+retnpts, ignorehide=True) if not s.FillAbove.hideerror: utils.brushExtFillPolygon(painter, s.FillAbove, clip, ptsabove+retnpts, ignorehide=True) # draw optional line (on top of fill) utils.plotClippedPolyline(painter, clip, ptsabove) utils.plotClippedPolyline(painter, clip, ptsbelow)
def _errorBarsFilled(style, xmin, xmax, ymin, ymax, xplotter, yplotter, s, painter, clip): """Draw filled region as error region.""" ptsabove = qt4.QPolygonF() ptsbelow = qt4.QPolygonF() hidevert = True # keep track of what's shown hidehorz = True if "vert" in style and (ymin is not None and ymax is not None) and not s.ErrorBarLine.hideVert: hidevert = False # lines above/below points utils.addNumpyToPolygonF(ptsbelow, xplotter, ymin) utils.addNumpyToPolygonF(ptsabove, xplotter, ymax) elif "horz" in style and (xmin is not None and xmax is not None) and not s.ErrorBarLine.hideHorz: hidehorz = False # lines left/right points utils.addNumpyToPolygonF(ptsbelow, xmin, yplotter) utils.addNumpyToPolygonF(ptsabove, xmax, yplotter) # draw filled regions above/left and below/right if "fill" in style and not (hidehorz and hidevert): # construct points for error bar regions retnpts = qt4.QPolygonF() utils.addNumpyToPolygonF(retnpts, xplotter[::-1], yplotter[::-1]) # polygons consist of lines joining the points and continuing # back along the plot line (retnpts) painter.save() painter.setPen(qt4.Qt.NoPen) if not s.FillBelow.hideerror: painter.setBrush(s.FillBelow.makeQBrush()) painter.drawPolygon(ptsbelow + retnpts) if not s.FillAbove.hideerror: painter.setBrush(s.FillAbove.makeQBrush()) painter.drawPolygon(ptsabove + retnpts) painter.restore() # draw optional line (on top of fill) utils.plotClippedPolyline(painter, clip, ptsabove) utils.plotClippedPolyline(painter, clip, ptsbelow)
def _plotLine(self, painter, xpts, ypts, bounds, clip): """ Plot the points in xpts, ypts.""" x1, y1, x2, y2 = bounds maxdeltax = (x2 - x1) * 3 / 4 maxdeltay = (y2 - y1) * 3 / 4 # idea is to collect points until we go out of the bounds # or reach the end, then plot them pts = qt4.QPolygonF() lastx = lasty = -65536 for x, y in itertools.izip(xpts, ypts): # ignore point if it outside sensible bounds if x < -32767 or y < -32767 or x > 32767 or y > 32767: if len(pts) >= 2: utils.plotClippedPolyline(painter, clip, pts) pts.clear() else: # if the jump wasn't too large, add the point to the points if abs(x - lastx) < maxdeltax and abs(y - lasty) < maxdeltay: pts.append(qt4.QPointF(x, y)) else: # draw what we have until now, and start a new line if len(pts) >= 2: utils.plotClippedPolyline(painter, clip, pts) pts.clear() pts.append(qt4.QPointF(x, y)) lastx = x lasty = y # draw remaining points if len(pts) >= 2: utils.plotClippedPolyline(painter, clip, pts)
def _plotLine(self, painter, xpts, ypts, bounds, clip): """ Plot the points in xpts, ypts.""" x1, y1, x2, y2 = bounds maxdeltax = (x2-x1)*3/4 maxdeltay = (y2-y1)*3/4 # idea is to collect points until we go out of the bounds # or reach the end, then plot them pts = qt4.QPolygonF() lastx = lasty = -65536 for x, y in itertools.izip(xpts, ypts): # ignore point if it outside sensible bounds if x < -32767 or y < -32767 or x > 32767 or y > 32767: if len(pts) >= 2: utils.plotClippedPolyline(painter, clip, pts) pts.clear() else: # if the jump wasn't too large, add the point to the points if abs(x-lastx) < maxdeltax and abs(y-lasty) < maxdeltay: pts.append( qt4.QPointF(x, y) ) else: # draw what we have until now, and start a new line if len(pts) >= 2: utils.plotClippedPolyline(painter, clip, pts) pts.clear() pts.append( qt4.QPointF(x, y) ) lastx = x lasty = y # draw remaining points if len(pts) >= 2: utils.plotClippedPolyline(painter, clip, pts)
try: self.checker.check(s.function, s.variable) except RuntimeError, e: self.logEvalError(e) return x1, y1, x2, y2 = posn cliprect = qt4.QRectF( qt4.QPointF(x1, y1), qt4.QPointF(x2, y2) ) painter = phelper.painter(self, posn) self.parent.setClip(painter, posn) apts, bpts = self.getFunctionPoints() px, py = self.parent.graphToPlotCoords(apts, bpts) # plot line painter.setBrush(qt4.QBrush()) painter.setPen( s.PlotLine.makeQPenWHide(painter) ) for x, y in utils.validLinePoints(px, py): if not s.Fill1.hide: self.parent.drawFillPts(painter, s.Fill1, cliprect, x, y) if not s.Fill2.hide: self.parent.drawFillPts(painter, s.Fill2, cliprect, x, y) if not s.PlotLine.hide: p = qt4.QPolygonF() utils.addNumpyToPolygonF(p, x, y) painter.setBrush(qt4.QBrush()) painter.setPen( s.PlotLine.makeQPen(painter) ) utils.plotClippedPolyline(painter, cliprect, p) document.thefactory.register( NonOrthFunction )