def makeColorbarImage(self, direction='horz'): """Make a QImage colorbar for the current plot. direction is 'horizontal' or 'vertical' to draw horizontal or vertical bars Returns a tuple (minval, maxval, scale, qimage) minval is the minimum value which should be plotted on the axis maxval is the maximum " " scale is 'linear' or 'log', depending on how numbers should be scaled qimage is a QImage of 1 x barsize """ self.recomputeInternals() minval, maxval = self.cacheddatarange s = self.settings # get colormap cmap = self.document.getColormap(s.colorMap, s.colorInvert) return utils.makeColorbarImage(minval, maxval, s.colorScaling, cmap, s.transparency, direction=direction)
def makeColorbarImage(self, direction='horz'): """Make a QImage colorbar for the current plot.""" s = self.settings c = s.Color cmap = self.document.getColormap( s.MarkerFill.colorMap, s.MarkerFill.colorMapInvert) return utils.makeColorbarImage( c.min, c.max, c.scaling, cmap, 0, direction=direction)
def makeColorbarImage(self, direction='horz'): """Make a QImage colorbar for the current plot.""" s = self.settings c = s.Color cmap = self.document.getColormap(s.MarkerFill.colorMap, s.MarkerFill.colorMapInvert) return utils.makeColorbarImage(c.min, c.max, c.scaling, cmap, 0, direction=direction)
def makeColorbarImage(self, direction="horz"): """Make a QImage colorbar for the current plot. direction is 'horizontal' or 'vertical' to draw horizontal or vertical bars Returns a tuple (minval, maxval, scale, qimage) minval is the minimum value which should be plotted on the axis maxval is the maximum " " scale is 'linear' or 'log', depending on how numbers should be scaled qimage is a QImage of 1 x barsize """ self.recomputeInternals() minval, maxval = self.cacheddatarange s = self.settings # get colormap cmap = self.document.getColormap(s.colorMap, s.colorInvert) return utils.makeColorbarImage(minval, maxval, s.colorScaling, cmap, s.transparency, direction=direction)
def _axisDraw(self, posn, parentposn, outerbounds, painter, phelper): """Do actual drawing.""" s = self.settings # get height of label font bounds = self.computeBounds(parentposn, phelper) font = s.get('Label').makeQFont(phelper) painter.setFont(font) fontheight = utils.FontMetrics(font, painter.device()).height() horz = s.direction == 'horizontal' # use above to estimate width and height if necessary w = s.get('width') if w.isAuto(): if horz: totalwidth = bounds[2] - bounds[0] - 2*fontheight else: totalwidth = fontheight else: totalwidth = w.convert(painter) h = s.get('height') if h.isAuto(): if horz: totalheight = fontheight else: totalheight = bounds[3] - bounds[1] - 2*fontheight else: totalheight = h.convert(painter) # work out horizontal position h = s.horzPosn if h == 'left': bounds[0] += fontheight bounds[2] = bounds[0] + totalwidth elif h == 'right': bounds[2] -= fontheight bounds[0] = bounds[2] - totalwidth elif h == 'centre': delta = (bounds[2]-bounds[0]-totalwidth)/2. bounds[0] += delta bounds[2] -= delta elif h == 'manual': bounds[0] += (bounds[2]-bounds[0])*s.horzManual bounds[2] = bounds[0] + totalwidth # work out vertical position v = s.vertPosn if v == 'top': bounds[1] += fontheight bounds[3] = bounds[1] + totalheight elif v == 'bottom': bounds[3] -= fontheight bounds[1] = bounds[3] - totalheight elif v == 'centre': delta = (bounds[3]-bounds[1]-totalheight)/2. bounds[1] += delta bounds[3] -= delta elif v == 'manual': bounds[1] += (bounds[3]-bounds[1])*s.vertManual bounds[3] = bounds[1] + totalheight # FIXME: this is ugly - update bounds in helper state phelper.states[(self,0)].bounds = bounds # do no painting if hidden or no image imgwidget = s.get('widgetName').findWidget() if s.hide: return bounds self.updateAxisLocation(bounds) # update image if necessary with new settings if imgwidget is not None: minval, maxval, axisscale, cmapname, trans, invert = \ imgwidget.getColorbarParameters() cmap = self.document.getColormap(cmapname, invert) img = utils.makeColorbarImage( minval, maxval, axisscale, cmap, trans, direction=s.direction) else: # couldn't find widget minval, maxval, axisscale = 0., 1., 'linear' img = None s.get('log').setSilent(axisscale == 'log') self.setAutoRange([minval, maxval]) self.computePlottedRange(force=True) # now draw image on axis... minpix, maxpix = self.graphToPlotterCoords( bounds, N.array([minval, maxval]) ) routside = qt4.QRectF( bounds[0], bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1] ) # really draw the img if img is not None: # coordinates to draw image and to clip rectangle if s.direction == 'horizontal': c = [ minpix, bounds[1], maxpix, bounds[3] ] cl = [ self.coordParr1, bounds[1], self.coordParr2, bounds[3] ] else: c = [ bounds[0], maxpix, bounds[2], minpix ] cl = [ bounds[0], self.coordParr1, bounds[2], self.coordParr2 ] r = qt4.QRectF(c[0], c[1], c[2]-c[0], c[3]-c[1]) rclip = qt4.QRectF(cl[0], cl[1], cl[2]-cl[0], cl[3]-cl[1]) painter.save() painter.setClipRect(rclip & routside) painter.drawImage(r, img) painter.restore() # if there's a border if not s.Border.hide: painter.setPen( s.get('Border').makeQPen(painter) ) painter.setBrush( qt4.QBrush() ) painter.drawRect( routside ) # actually draw axis axis.Axis._axisDraw(self, bounds, parentposn, outerbounds, painter, phelper)