Example #1
0
 def getKeyText(self, number):
     """Get key entry."""
     s = self.settings
     if s.keyLevels:
         cl = s.get("ContourLabels")
         return utils.formatNumber(s.levelsOut[number] * cl.scale, cl.format, locale=self.document.locale)
     else:
         return ""
Example #2
0
        def generateTickLabels():
            """Return plotter position of labels and label text."""
            # get format for labels
            format = s.TickLabels.format
            if format.lower() == 'auto':
                format = self.autoformat

            # generate positions and labels
            for posn, tickval in izip(coordticks, self.majortickscalc):
                text = utils.formatNumber(tickval*scale, format,
                                          locale=self.document.locale)
                yield posn, text
Example #3
0
 def _getLabels(self, ticks, autoformat):
     """Return tick labels."""
     labels = []
     tl = self.settings.TickLabels
     format = tl.format
     scale = tl.scale
     if format.lower() == 'auto':
         format = autoformat
     for v in ticks:
         l = utils.formatNumber(v*scale, format, locale=self.document.locale)
         labels.append(l)
     return labels
Example #4
0
 def _getLabels(self, ticks, autoformat):
     """Return tick labels."""
     labels = []
     tl = self.settings.TickLabels
     format = tl.format
     scale = tl.scale
     if format.lower() == 'auto':
         format = autoformat
     for v in ticks:
         l = utils.formatNumber(v*scale, format, locale=self.document.locale)
         labels.append(l)
     return labels
Example #5
0
    def updateOutputLabel(self, ops, vals, chi2, dof):
        """Use best fit parameters to update text label."""
        s = self.settings
        labelwidget = s.get('outLabel').findWidget()

        if labelwidget is not None:
            # build up a set of X=Y values
            loc = self.document.locale
            txt = []
            for l, v in sorted(vals.iteritems()):
                val = utils.formatNumber(v, '%.4Vg', locale=loc)
                txt.append( '%s = %s' % (l, val) )
            # add chi2 output
            txt.append( r'\chi^{2}_{\nu} = %s/%i = %s' % (
                    utils.formatNumber(chi2, '%.4Vg', locale=loc),
                    dof,
                    utils.formatNumber(chi2/dof, '%.4Vg', locale=loc) ))

            # update label with text
            text = r'\\'.join(txt)
            ops.append( document.OperationSettingSet(
                    labelwidget.settings.get('label') , text ) )
Example #6
0
    def plotContourLabel(self, painter, number, xplt, yplt, showline):
        """Draw a label on a contour.
        This clips when drawing the line, plotting the label on top.
        """
        s = self.settings
        cl = s.get('ContourLabels')

        painter.save()

        # get text and font
        text = utils.formatNumber(number * cl.scale, cl.format,
                                  locale=self.document.locale)
        font = cl.makeQFont(painter)
        descent = utils.FontMetrics(font, painter.device()).descent()

        # work out where text lies
        half = len(xplt)/2
        hx, hy = xplt[half], yplt[half]
        r = utils.Renderer(painter, font, hx, hy, text, alignhorz=0,
                           alignvert=0, angle=0)
        bounds = r.getBounds()

        # heuristics of when to plot label
        # we try to only plot label if underlying line is long enough
        height = bounds[3]-bounds[1]
        showtext = ( height*1.5 < (yplt.max() - yplt.min()) or
                     (height*4 < (xplt.max() - xplt.min())) )

        if showtext:
            # clip region containing text
            oldclip = painter.clipRegion()
            cr = oldclip - qt4.QRegion( bounds[0]-descent, bounds[1]-descent,
                                        bounds[2]-bounds[0]+descent*2,
                                        bounds[3]-bounds[1]+descent*2 )
            painter.setClipRegion(cr)

        # draw lines
        if showline:
            pts = qt4.QPolygonF()
            utils.addNumpyToPolygonF(pts, xplt, yplt)
            painter.drawPolyline(pts)

        # actually plot the label
        if showtext:
            painter.setClipRegion(oldclip)
            painter.setPen( cl.makeQPen() )
            r.render()

        painter.restore()
Example #7
0
    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)
Example #8
0
    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)