def barDrawStacked(self, painter, posns, maxwidth, dsvals, axes, widgetposn, clip): """Draw each dataset in a single bar.""" s = self.settings # get positions of groups of bars barwidth = maxwidth * s.barfill ishorz = s.direction == "horizontal" # keep track of last most negative or most positive values in bars poslen = len(posns) lastneg = N.zeros(poslen) lastpos = N.zeros(poslen) # keep track of bars for error bars barvals = [] for dsnum, data in enumerate(dsvals): # set correct attributes for datasets painter.setBrush(s.BarFill.get("fills").makeBrush(dsnum)) painter.setPen(s.BarLine.get("lines").makePen(painter, dsnum)) # add on value to last value in correct direction data = data["data"] last = N.where(data < 0.0, lastneg, lastpos) new = N.where(data < 0.0, lastneg + data, lastpos + data) # work out maximum extents for next time lastneg = N.min(N.vstack((lastneg, new)), axis=0) lastpos = N.max(N.vstack((lastpos, new)), axis=0) # convert values to plotter coordinates lastplt = axes[not ishorz].dataToPlotterCoords(widgetposn, last) newplt = axes[not ishorz].dataToPlotterCoords(widgetposn, new) # positions of bar perpendicular to bar direction posns1 = posns - barwidth * 0.5 posns2 = posns1 + barwidth # we iterate over each of these coordinates if ishorz: p = (lastplt, posns1, newplt, posns2) else: p = (posns1, lastplt, posns2, newplt) # draw bars utils.plotBoxesToPainter(painter, p[0], p[1], p[2], p[3], clip) barvals.append(new) for barval, dsval in izip(barvals, dsvals): # draw error bars self.drawErrorBars(painter, posns, barwidth, barval, dsval, axes, widgetposn)
def _errorBarsBoxFilled(style, xmin, xmax, ymin, ymax, xplotter, yplotter, s, painter, clip): """Draw box filled region inside error bars.""" if None not in (xmin, xmax, ymin, ymax): painter.save() painter.setPen(qt4.QPen(qt4.Qt.NoPen)) # filled region below if not s.FillBelow.hideerror: painter.setBrush(s.FillBelow.makeQBrush()) utils.plotBoxesToPainter(painter, xmin, ymin, xmax, yplotter, clip) # filled region above if not s.FillAbove.hideerror: painter.setBrush(s.FillAbove.makeQBrush()) utils.plotBoxesToPainter(painter, xmin, yplotter, xmax, ymax, clip) painter.restore()
def barDrawGroup(self, painter, posns, maxwidth, dsvals, axes, widgetposn, clip): """Draw groups of bars.""" s = self.settings # calculate bar and group widths numgroups = len(dsvals) groupwidth = maxwidth usablewidth = groupwidth * s.groupfill bardelta = usablewidth / float(numgroups) barwidth = bardelta * s.barfill ishorz = s.direction == "horizontal" # bar extends from these coordinates zeropt = axes[not ishorz].dataToPlotterCoords(widgetposn, N.array([0.0])) for dsnum, dataset in enumerate(dsvals): # set correct attributes for datasets painter.setBrush(s.BarFill.get("fills").makeBrush(dsnum)) painter.setPen(s.BarLine.get("lines").makePen(painter, dsnum)) # convert bar length to plotter coords lengthcoord = axes[not ishorz].dataToPlotterCoords(widgetposn, dataset["data"]) # these are the coordinates perpendicular to the bar posns1 = posns + (-usablewidth * 0.5 + bardelta * dsnum + (bardelta - barwidth) * 0.5) posns2 = posns1 + barwidth if ishorz: p = (zeropt + N.zeros(posns1.shape), posns1, lengthcoord, posns2) else: p = (posns1, zeropt + N.zeros(posns2.shape), posns2, lengthcoord) # iterate over coordinates to plot bars utils.plotBoxesToPainter(painter, p[0], p[1], p[2], p[3], clip) # draw error bars self.drawErrorBars(painter, posns2 - barwidth * 0.5, barwidth, dataset["data"], dataset, axes, widgetposn)
def _errorBarsBox(style, xmin, xmax, ymin, ymax, xplotter, yplotter, s, painter, clip): """Draw box around error region.""" if None not in (xmin, xmax, ymin, ymax): painter.setBrush(qt4.QBrush()) utils.plotBoxesToPainter(painter, xmin, ymin, xmax, ymax, clip)