使用Matplotlib,我有两个子图,我希望它们具有相同的自定义字符串xticks。
下面是我尝试过的最小示例:
下面是我尝试过的最小示例:
import matplotlib.pyplot as plt
f, axs = plt.subplots(ncols=2, sharex=True)
plt.xticks(range(6), [str(x)+"foo" for x in range(6)], rotation='45')
for i in range(2):
ax = axs[i]
ax.plot(range(6), range(6))
f.show()
生成以下输出:
请注意,左侧的xticks未旋转。我该怎么做呢?
如果我删除 sharex=True
,则左侧子图没有自定义xticks。 然而,我不能给单个轴设置xticks。这将导致错误:
AttributeError: 'AxesSubplot' object has no attribute 'xticks'