问题
I have plot in PyX in python
g = graph.graphxy(width=8,
x=graph.axis.log(min=1e-1, max=1e4, title=r"$x$-axis"),
y=graph.axis.lin(max=5, title=r"$y$-axis"))
g.plot(graph.data.function("y(x)=tan(log(1/x))**2"))
g.writeEPSfile("axis")
How to keep ticks in black, but change color of tick text (i.e. the numbers 0, 1, 2, 3, 4, 5 on y-axis ) to white?
Or, even better. How to remove the tick text (i.e. the numbers 0, 1, 2, 3, 4, 5 on y-axis ) but keep the tick marks ?
回答1:
To alter the text styling while drawing the labels, you need to pass labelattrs to the painter:
painter=graph.axis.painter.regular(labelattrs=[color.grey.white])
As all the axis (usually) use the regular painter, this code/setting can be passed to both, the linear and the log axis.
The painter can also be used to disable the labels. You can set the labelattrs to None, which will skip drawing the labels. This is fine, and happens rather late in the process of building the axes. Another option would be to pass a non-default parter to disable/alter the creation of the automatic axis ticks and labels. Here, again, passing None to the labels setting disables the labels. However, for such code to work properly, you need to have different settings for linear and log axes, as they use different axis parters. So setting the labelattrs of the painter is certainly the easiest, even though it is kind of quick and dirty.
来源:https://stackoverflow.com/questions/50526962/python-pyx-plot-change-axes-tick-text-color