Search code examples
pythonplotpyx

How do I hide the axis text in Python PyX


I'm just trying to get a graph but without any numbers in the axes. Let's say:

from math import pi
from pyx import *

g = graph.graphxy(width=8)
g.plot(graph.data.paramfunction("k", 0, 2*pi, "x, y = sin(2*k), cos(3*k)"))
g.writePDFfile("lissajous")

How do I get rid of axis labels?


Solution

  • To get rid of the text at the axis label, the most easiest solution is to set the labelattrs of the axis painter to None, as discussed at the answer of Python PyX plot: change axes tick text color:

    from math import pi
    from pyx import *
    
    a = graph.axis.linear(painter=graph.axis.painter.regular(labelattrs=None))
    g = graph.graphxy(width=8, x=a, y=a)
    g.plot(graph.data.paramfunction("k", 0, 2*pi, "x, y = sin(2*k), cos(3*k)"))
    g.writePDFfile("lissajous")
    

    You keep the axis ticks here. If you want to get rid of the ticks as well, you could disable the painter alltogether, and the linkedpainter as well (otherwise you will keep the axis on the other side of the graph, which display the ticks only):

    from math import pi
    from pyx import *
    
    a = graph.axis.linear(painter=None, linkpainter=None)
    g = graph.graphxy(width=8, x=a, y=a)
    g.plot(graph.data.paramfunction("k", 0, 2*pi, "x, y = sin(2*k), cos(3*k)"))
    g.writePDFfile("lissajous")
    

    This, however, means, that you loose the axis altogether. A simple way out is to add a backgroundattrs=[deco.stroked()] to the graph, even though, technically, it is something very different, and kind of wrong.

    Unfortunately, the whole axis partition calculation, is kept running, which also means, that it will keep extending the axis ranges depending on the data ranges. The way out should be to use the most simple axis scheme, with labels and ticks at the beginning and end of the axis ranges, and just disable those. This will probably be handy in all kind of simple cases, and it is kind of wired we don't have that. I will add such a parter in a future PyX release.