我使用
autofmt_xdate
来以易读的方式绘制长x轴标签。问题是当我想要组合不同的子图时,其他子图的x轴标签消失了,我不希望在下面的图中最左边的(两行高)子图上出现这种情况。有没有办法防止 autofmt_xdate
抑制其他x轴标签?或者有另一种旋转标签的方法吗?如您所见,我也尝试使用了 xticks
和 "rotate",但结果并不令人满意,因为标签围绕它们的中心旋转,导致标签混乱无序。
生成此图的脚本:
from matplotlib import pyplot as plt
from numpy import arange
import numpy
from matplotlib import rc
rc("figure",figsize=(15,10))
#rc('figure.subplot',bottom=0.1,hspace=0.1)
rc("legend",fontsize=16)
fig = plt.figure()
Test_Data = numpy.random.normal(size=20)
fig = plt.figure()
Dimension = (2,3)
plt.subplot2grid(Dimension, (0,0),rowspan=2)
plt.plot(Test_Data)
plt.subplot2grid(Dimension, (0,1),colspan=2)
for i,j in zip(Test_Data,arange(len(Test_Data))):
plt.bar(i,j)
plt.legend(arange(len(Test_Data)))
plt.subplot2grid(Dimension, (1,1),colspan=2)
xticks = [r"%s (%i)" % (a,b) for a,b in zip(Test_Data,Test_Data)]
plt.xticks(arange(len(Test_Data)),xticks)
fig.autofmt_xdate()
plt.ylabel(r'$Some Latex Formula/Divided by some Latex Formula$',fontsize=14)
plt.plot(Test_Data)
#plt.setp(plt.xticks()[1],rotation=30)
plt.tight_layout()
#plt.show()
plt.setp(ax.get_xticklabels(), rotation=30, ha='right')
- Chaostefig.autofmt_xdate()
的使用,因为它有一个副作用:您只能看到底部子图的 x 刻度。你的答案帮了我很大的忙。 - chill appreciator