Python PyX 绘图:更改轴刻度文本颜色 [英] Python PyX plot: change axes tick text color

查看:95
本文介绍了Python PyX 绘图:更改轴刻度文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中的 PyX 中有绘图

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")

如何将刻度保持为黑色,但将刻度文本的颜色(即 y 轴上的数字 0、1、2、3、4、5)更改为白色?

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?

或者,甚至更好.如何删除刻度文本(即 y 轴上的数字 0、1、2、3、4、5)但保留刻度?

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 ?

推荐答案

要在绘制标签时更改文本样式,您需要将 labelattrs 传递给画家:

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.

画家也可用于禁用标签.您可以将 labelattrs 设置为 None,这将跳过绘制标签.这很好,并且在构建轴的过程中发生得相当晚.另一种选择是传递一个非默认的parter 来禁用/更改自动轴刻度和标签的创建.在这里,再次将 None 传递给标签设置会禁用标签.但是,要使此类代码正常工作,您需要对线性轴和对数轴进行不同的设置,因为它们使用不同的轴部分.所以设置painter的labelattrs当然是最简单的,尽管它有点快速和肮脏.

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.

这篇关于Python PyX 绘图:更改轴刻度文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆