PyX - Example: axis/painter.py

0.3 KB
18.6 KB
11.8 KB

Painting of an axis

painter.png
from pyx import *

mypainter = graph.axis.painter.regular(outerticklength=graph.axis.painter.ticklength.normal)

c = graph.axis.pathaxis(path.curve(0, 0, 3, 0, 1, 4, 4, 4),
                        graph.axis.linear(min=0, max=10, title="axis title", painter=mypainter))
c.writeEPSfile("painter")
c.writePDFfile("painter")

Description

Axis painters performs the painting of an axis, which means they take all the information of the axis an create a proper drawing for that.

While an usual axis painter has quite some parameters to adjust the output, here we only alter the ticks. By default, ticks are stroked only towards the inside of the graph (in the path examples there is no graph but don't mind). The labels and the axis title are plotted outside of the graph. Futhermore the axis title (when present as in this example) is rotated along the axis (without writing it upside down), while the tick labels are not rotated at all.

In this example we set an outerticklength. Together with the innerticklength set to the same value by default the ticks are stroked across the axis. As it is common to sub-components of the axis, you need to pass the adapted instances (stored in the variable mypainter here) to the axis in its constructor.