def _computeTickVals(self): """Compute tick values.""" s = self.settings # this is a hack as we lose ends off the axis otherwise d = 1e-6 # get ticks along left axis atickleft = AxisTicks(self._orgleft-d, self._orgleft+self._size+d, s.MajorTicks.number, s.MinorTicks.number, extendmin=False, extendmax=False) atickleft.getTicks() # use the interval from above to calculate ticks for right atickright = AxisTicks(self._orgright-d, self._orgright+self._size+d, s.MajorTicks.number, s.MinorTicks.number, extendmin=False, extendmax=False, forceinterval = atickleft.interval) atickright.getTicks() # then calculate for bottom atickbot = AxisTicks(self._orgbot-d, self._orgbot+self._size+d, s.MajorTicks.number, s.MinorTicks.number, extendmin=False, extendmax=False, forceinterval = atickleft.interval) atickbot.getTicks() return atickbot, atickleft, atickright
def drawAxes(self, painter, bounds, datarange, outerbounds=None): '''Plot axes.''' s = self.settings t = s.Tick if self._maxradius <= 0.: self._maxradius = 1. atick = AxisTicks(0, self._maxradius, t.number, t.number*4, extendbounds=False, extendzero=False) atick.getTicks() majtick = atick.tickvals # draw ticks as circles if not t.hideannuli: painter.setPen( s.Tick.makeQPenWHide(painter) ) painter.setBrush( qt4.QBrush() ) for tick in majtick[1:]: radius = tick / self._maxradius painter.drawEllipse(qt4.QRectF( qt4.QPointF( self._xc - radius*self._xscale, self._yc - radius*self._yscale ), qt4.QPointF( self._xc + radius*self._xscale, self._yc + radius*self._yscale ) )) # setup axes plot tl = s.TickLabels scale, format = tl.scale, tl.format if format == 'Auto': format = atick.autoformat painter.setPen( tl.makeQPen() ) font = tl.makeQFont(painter) # draw radial axis if not s.TickLabels.hideradial: for tick in majtick[1:]: num = utils.formatNumber(tick*scale, format, locale=self.document.locale) x = tick / self._maxradius * self._xscale + self._xc r = utils.Renderer(painter, font, x, self._yc, num, alignhorz=-1, alignvert=-1, usefullheight=True) r.render() if s.units == 'degrees': angles = [ u'0°', u'30°', u'60°', u'90°', u'120°', u'150°', u'180°', u'210°', u'240°', u'270°', u'300°', u'330°' ] else: angles = [ '0', u'π/6', u'π/3', u'π/2', u'2π/3', u'5π/6', u'π', u'7π/6', u'4π/3', u'3π/2', u'5π/3', u'11π/6' ] align = [ (-1, 1), (-1, 1), (-1, 1), (0, 1), (1, 1), (1, 1), (1, 0), (1, -1), (1, -1), (0, -1), (-1, -1), (-1, -1) ] if s.direction == 'anticlockwise': angles = angles[0:1] + angles[1:][::-1] # rotate labels if zero not at right if s.position0 == 'top': angles = angles[3:] + angles[:4] elif s.position0 == 'left': angles = angles[6:] + angles[:7] elif s.position0 == 'bottom': angles = angles[9:] + angles[:10] # draw labels around plot if not s.TickLabels.hidetangential: for i in xrange(12): angle = 2 * N.pi / 12 x = self._xc + N.cos(angle*i) * self._xscale y = self._yc + N.sin(angle*i) * self._yscale r = utils.Renderer(painter, font, x, y, angles[i], alignhorz=align[i][0], alignvert=align[i][1], usefullheight=True) r.render() # draw spokes if not t.hidespokes: painter.setPen( s.Tick.makeQPenWHide(painter) ) painter.setBrush( qt4.QBrush() ) angle = 2 * N.pi / 12 lines = [] for i in xrange(12): x = self._xc + N.cos(angle*i) * self._xscale y = self._yc + N.sin(angle*i) * self._yscale lines.append( qt4.QLineF(qt4.QPointF(self._xc, self._yc), qt4.QPointF(x, y)) ) painter.drawLines(lines)
def drawAxes(self, painter, bounds, datarange, outerbounds=None): '''Plot axes.''' s = self.settings t = s.Tick if self._maxradius <= 0.: self._maxradius = 1. atick = AxisTicks(0, self._maxradius, t.number, t.number * 4, extendmin=False, extendmax=False) atick.getTicks() majtick = atick.tickvals # draw ticks as circles if not t.hideannuli: painter.setPen(s.Tick.makeQPenWHide(painter)) painter.setBrush(qt4.QBrush()) for tick in majtick[1:]: radius = tick / self._maxradius painter.drawEllipse( qt4.QRectF( qt4.QPointF(self._xc - radius * self._xscale, self._yc - radius * self._yscale), qt4.QPointF(self._xc + radius * self._xscale, self._yc + radius * self._yscale))) # setup axes plot tl = s.TickLabels scale, format = tl.scale, tl.format if format == 'Auto': format = atick.autoformat painter.setPen(tl.makeQPen()) font = tl.makeQFont(painter) # draw radial axis if not s.TickLabels.hideradial: for tick in majtick[1:]: num = utils.formatNumber(tick * scale, format, locale=self.document.locale) x = tick / self._maxradius * self._xscale + self._xc r = utils.Renderer(painter, font, x, self._yc, num, alignhorz=-1, alignvert=-1, usefullheight=True) r.render() if s.units == 'degrees': angles = [ u'0°', u'30°', u'60°', u'90°', u'120°', u'150°', u'180°', u'210°', u'240°', u'270°', u'300°', u'330°' ] else: angles = [ '0', u'π/6', u'π/3', u'π/2', u'2π/3', u'5π/6', u'π', u'7π/6', u'4π/3', u'3π/2', u'5π/3', u'11π/6' ] align = [(-1, 1), (-1, 1), (-1, 1), (0, 1), (1, 1), (1, 1), (1, 0), (1, -1), (1, -1), (0, -1), (-1, -1), (-1, -1)] if s.direction == 'anticlockwise': angles = angles[0:1] + angles[1:][::-1] # rotate labels if zero not at right if s.position0 == 'top': angles = angles[3:] + angles[:4] elif s.position0 == 'left': angles = angles[6:] + angles[:7] elif s.position0 == 'bottom': angles = angles[9:] + angles[:10] # draw labels around plot if not s.TickLabels.hidetangential: for i in xrange(12): angle = 2 * N.pi / 12 x = self._xc + N.cos(angle * i) * self._xscale y = self._yc + N.sin(angle * i) * self._yscale r = utils.Renderer(painter, font, x, y, angles[i], alignhorz=align[i][0], alignvert=align[i][1], usefullheight=True) r.render() # draw spokes if not t.hidespokes: painter.setPen(s.Tick.makeQPenWHide(painter)) painter.setBrush(qt4.QBrush()) angle = 2 * N.pi / 12 lines = [] for i in xrange(12): x = self._xc + N.cos(angle * i) * self._xscale y = self._yc + N.sin(angle * i) * self._yscale lines.append( qt4.QLineF(qt4.QPointF(self._xc, self._yc), qt4.QPointF(x, y))) painter.drawLines(lines)