0
在创建具有多个垂直轴的图形(沿着http://matplotlib.org/examples/axes_grid/demo_parasite_axes2.html的线条)我试图旋转水平轴上的标签。但是,应该这样做的代码似乎没有做任何事情。针对主机子插件的轴刻度标签对齐
例如:
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt
num_sub_axes = 3
host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(left=0.05, right=max(0.75, 1-0.075*num_sub_axes))
host.axis["left"].toggle(all=False)
for sub_ax_idx in range(num_sub_axes):
new_ax = host.twinx()
new_fixed_axis = new_ax.get_grid_helper().new_fixed_axis
new_ax.axis["right"] = new_fixed_axis(loc="right", axes=new_ax, offset=(45 * sub_ax_idx, 0))
new_ax.axis["right"].toggle(all=True)
line, = new_ax.plot([0, 1, 2], [(sub_ax_idx+1)**2, (sub_ax_idx+1)**2.5, (sub_ax_idx+1)**3], label=str(sub_ax_idx))
new_ax.axis["right"].label.set_color(line.get_color())
new_ax.axis["right"].major_ticklabels.set_color(line.get_color())
new_ax.axis["right"].minor_ticklabels.set_color(line.get_color())
host.set_xticks([0, 1, 2])
host.set_xticklabels(["One", "Two", "Three"], rotation=-45, horizontalalignment="right", verticalalignment="bottom")
host.legend()
plt.draw()
plt.show()
请注意,水平标签( “一”, “二”, “三”)是显然的水平,即使我使用rotation=-45
关键字参数在我的电话set_xticklabels
中指定的文档:http://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.set_xticklabels.html
我怀疑这可能与事实t这个帽子不仅仅是一个普通的axes
对象。
但是,如果不是如上所述,我该如何旋转这些标签?
我敢肯定,只是在看文档是不会转动我的标签。 :) 这就是说,我不立即看到如何做我想从文档做什么。可能会发布一些示例代码? – acdr
我应该说的是,这是因为它不是一个标准的'Axes'对象,所以你必须查看特定子类的文档。相关部分在我的评论中被链接。不幸的是,我没有时间写出完整的答案。 – Goyo