PyX - Example: axis/texter.py

0.7 KB
30.0 KB
17.7 KB

Texter

texter.png
import math
from pyx import *
from pyx.graph import axis

class piaxis(axis.linear):

    def __init__(self, divisor=math.pi,
                 texter=axis.texter.rational(suffix="\pi"), **kwargs):
        axis.linear.__init__(self, divisor=divisor, texter=texter, **kwargs)


p = path.path(path.moveto(0, 0), path.curveto(3, 0, 1, 4, 4, 4))

c = canvas.canvas()
c.insert(axis.pathaxis(p, axis.linear(min=0, max=10)))
c.insert(axis.pathaxis(p.transformed(trafo.translate(4, 0)),
                       axis.linear(min=0, max=1e5)))
c.insert(axis.pathaxis(p.transformed(trafo.translate(8, 0)),
                       piaxis(min=0, max=2*math.pi)))
c.writeEPSfile("texter")
c.writePDFfile("texter")

Description

Texters create the label strings written to the ticks. There are texters available for decimal numbers without and with an exponential part as well as fractions.

At the right axis we also show how to create a special piaxis. Here some axis parameters are altered to fit an pi-scaled axis nicely. Futhermore instead of just creating a special axis instance by setting the divisor and texter parameters, a piaxis class is created which just alters the defaults of the linear axis it is based at.