4
使用Matplotlib,我有两个子图,我希望它们具有相同的自定义字符串xticks。多个子图的自定义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'
我生活中可以没有sharex。谢谢! – qznc