如何在刻度标签和轴之间添加空间
我已成功增加刻度标签的字体,但现在它们距离轴太近了。我想在刻度标签和轴之间添加一点呼吸空间。
I've increased the font of my ticklabels successfully, but now they're too close to the axis. I'd like to add a little breathing room between the ticklabels and the axis.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您不想全局更改间距(通过编辑 rcParams),并且想要更简洁的方法,请尝试以下操作:
ax.tick_params(axis='both', which='major', pad=15)
或仅用于 x 轴
ax.tick_params(axis='x', which='major', pad=15)
或 y 轴
ax.tick_params(axis=' y', which='major', pad=15)
If you don't want to change the spacing globally (by editing your rcParams), and want a cleaner approach, try this:
ax.tick_params(axis='both', which='major', pad=15)
or for just x axis
ax.tick_params(axis='x', which='major', pad=15)
or the y axis
ax.tick_params(axis='y', which='major', pad=15)
看起来 matplotlib 将这些设置视为 rcParams:
在创建任何图形之前设置这些设置,应该没问题。
我查看了源代码,似乎没有任何其他方法可以以编程方式设置它们。 (tick.set_pad() 看起来它试图做正确的事情,但填充似乎是在构造 Ticks 时设置的,之后无法更改。)
It looks like matplotlib respects these settings as rcParams:
Set those before you create any figures and you should be fine.
I've looked at the source code and there doesn't appear to be any other way to set them programmatically. (tick.set_pad() looks like it tries to do the right thing, but the padding seems to be set when the Ticks are constructed and can't be changed after that.)
这可以使用
set_pad
完成,但随后您必须重置标签...This can be done using
set_pad
but you then have to reset the label...axes
图非常有用,但是对于figure
还有其他选项,它们都可以通过指定x=
和y=
参数。fig.suptitle
< /a>fig.supxlabel
< /a>fig.supylabel
< /a>axes
plots, but there are other options for afigure
, which can all be positioned by specifying thex=
andy=
parameter.fig.suptitle
fig.supxlabel
fig.supylabel
在标记轴时,您可以指定 labelpad = n,以便在刻度标签和轴之间留出一些空间。
You can specify
labelpad = n
, when labelling your axes, for giving some space between ticklabels and the axis.