Matplotlib在绘图区域内移动刻度线标签
问题描述:
是否可以在打印区域内放置刻度线标签?我已经尝试过:
Is it possible to put tick labels inside the plotting area? I have already tried:
ax.tick_params(axis="y",pad=-.5, left="off",labelleft="on")
和
ax.tick_params(axis="y",direction="in", left="off",labelleft="on")
前者只是将轴向内移动,而后者只是使刻度线移动而不是刻度标签.
The former just moves the axis inward, and the latter only moves the ticks not the tick labels.
答
我想您完全在正确的轨道上.问题只是为了找到填充的良好参数,以便使刻度标签位于轴内.填充以点为单位,因此使用大于0.5的数字是有意义的.此外,由于文本的对齐方式,x和y轴的填充也不同.
I guess you are completely on the right track. The problem is just to find the good parameters for the padding in order to have the ticklabels inside the axes. The padding is measured in points, so it makes sense to use much larger numbers than 0.5. Also the padding is different for x and y axis due to the text's alignment.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.tick_params(axis="y",direction="in", pad=-22)
ax.tick_params(axis="x",direction="in", pad=-15)
plt.show()