PyX - Example: axis/log.py
Logarithmic axes
import math from pyx import * from pyx.graph import axis p = path.curve(0, 0, 3, 0, 1, 4, 4, 4) log2parter = axis.parter.log([axis.parter.preexp([axis.tick.rational(1)], 4), axis.parter.preexp([axis.tick.rational(1)], 2)]) log2texter = axis.texter.exponential(nomantissaexp=r"{2^{%s}}", mantissamax=axis.tick.rational(2)) c = canvas.canvas() c.insert(axis.pathaxis(p, axis.log(min=1, max=1024))) c.insert(axis.pathaxis(p.transformed(trafo.translate(4, 0)), axis.log(min=1, max=1024, parter=log2parter))) c.insert(axis.pathaxis(p.transformed(trafo.translate(8, 0)), axis.log(min=1, max=1024, parter=log2parter, texter=log2texter))) c.writeEPSfile("log") c.writePDFfile("log")
Description
Logarithmic axes are quite similar to linear axes and differ only in a very few properties, namely the non-linear convert method in which they transform values to positions on the axis, a different default partitioner and a different default rater. While the partitioner really is quite different - it implements a logarithmic positioning of the ticks - the rater just alters some defaults in favour of using more subticks to improve the visualization of the logarithmic nature of the axis.
Beside presenting a standard logarithmic axis we also show you how to alter the base used by the logarithmic axis. Since the functionality of a logarithmic axis is independend of the base, all we need to adjust are certain components creating ticks, the texts for the labels etc.
