简体   繁体   English

如何在浮动圆柱轴中旋转刻度标签?

[英]How to rotate tick labels in floating cylindrical axes?

http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html

Check out the VERY bottom of this link.查看此链接的非常底部。 I'm interested in that axes in the middle, where the axis objects are curved into the shape of a quarter-washer.我对中间的轴感兴趣,其中轴对象弯曲成四分之一垫圈的形状。 If you check the sourcecode, this axes object is made by setup_axes2:如果您检查源代码,这个轴对象是由 setup_axes2 制作的:

def setup_axes2(fig, rect):
"""
With custom locator and formatter.
Note that the extreme values are swapped.
"""
tr = PolarAxes.PolarTransform()

pi = np.pi
angle_ticks = [(0, r"$0$"),
           (.25*pi, r"$\frac{1}{4}\pi$"),
           (.5*pi, r"$\frac{1}{2}\pi$")]
grid_locator1 = FixedLocator([v for v, s in angle_ticks])
tick_formatter1 = DictFormatter(dict(angle_ticks))

grid_locator2 = MaxNLocator(2)

grid_helper = floating_axes.GridHelperCurveLinear(
    tr, extremes=(.5*pi, 0, 2, 1),
    grid_locator1=grid_locator1,
    grid_locator2=grid_locator2,
    tick_formatter1=tick_formatter1,
    tick_formatter2=None)

ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
fig.add_subplot(ax1)

# create a parasite axes whose transData in RA, cz
aux_ax = ax1.get_aux_axes(tr)

aux_ax.patch = ax1.patch  # for aux_ax to have a clip path as in ax
ax1.patch.zorder = 0.9  # but this has a side effect that the patch is
# drawn twice, and possibly over some other
# artists. So, we decrease the zorder a bit to
# prevent this.

return ax1, aux_ax

When I label the ticks in the theta axis, the labels are always upside down.当我在 theta 轴上标记刻度时,标签总是颠倒的。 I don't know how to flip them.我不知道如何翻转它们。 I also don't know how to flip the axis labels upside down.我也不知道如何颠倒轴标签。 Does anyone know about these confusing floating axes?有谁知道这些令人困惑的浮动轴?

The hint was in setup_axes3() from the example you linked.提示位于您链接的示例中的setup_axes3() The individual axes in the FloatingSubplot are referred to like ax.axis[side] where side is one of ["top","bottom","left","right"] . FloatingSubplot中的各个轴被称为ax.axis[side] ,其中side["top","bottom","left","right"] From there you get the usual.从那里你得到通常的。

ax = ax2.axis["bottom"]
ax.major_ticklabels.set_rotation(180)
ax.set_label("foo")
ax.label.set_rotation(180)
ax.LABELPAD += 10

Just do dir(ax) to see what you have access to.只需执行dir(ax)即可查看您可以访问的内容。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM