一旦我運行下面的代碼,第三個繪圖ax3的x刻度標籤就不會顯示出來。但是,我只刪除了ax1和ax2的x刻度標籤。有任何解決方案讓日期出現在我的第三個繪圖ax3的x軸上?Matplotlib缺少x刻度標籤
plt.figure()
ax1 = plt.subplot2grid((8,1),(0,0), rowspan=4, colspan=1)
ax1.yaxis.set_major_locator(mticker.MaxNLocator(nbins=10, prune='lower'))
plt.setp(ax1.get_xticklabels(), visible=False)
ax2 = plt.subplot2grid((8,1),(4,0), rowspan=2, colspan=1, sharex = ax1)
plt.setp(ax2.get_xticklabels(), visible=False)
ax3 = plt.subplot2grid((8,1),(6,0), rowspan=2, colspan=1, sharex = ax1)
ax3.xaxis.set_major_locator(mticker.MaxNLocator(10))
ax3.xaxis.set_minor_locator(mticker.MaxNLocator(20))
'''
# This has been ***removed*** in corrected version
for label in ax3.xaxis.get_ticklabels():
label.set_rotation(45)
plt.xlabel('Dates') #This label does not appear in the figure either
'''
ax3.yaxis.set_major_locator(mticker.MaxNLocator(nbins=5, prune='upper'))
main.dropna(inplace=True)
main['sales1'].plot(ax=ax1)
main['sales2'].plot(ax=ax1)
cmain.plot(ax=ax2)
main[['rollsales1', 'rollsales2']].plot(ax=ax3)
'''
# This has been added to corrected version.
plt.setp(ax3.xaxis.get_label(), visible=True, text='Dates')
plt.setp(ax3.get_xticklabels(), visible=True, rotation=30, ha='right')
'''
plt.show()
您在這裏有太多的代碼。請提供**最少**,完整且可驗證的示例。 – James
縮短到我認爲問題可能出現的地方。感謝您的意見。 – econ99
你使用的是什麼版本的matplotlib? – James