我已經繪製了在特定地點超過16年的碳通量時間序列。我希望X軸有年(1992-2007)而不是年份(1-16)。當我將x軸設置爲1992的最小值和2007的最大值時,該圖不會出現在圖上,但是當我不設置最小/最大年時,它就會出現。我不知道我做錯了什麼。我繪製了一年以上的另一個時間序列,並且能夠使用MonthLocator爲月份標記x軸,但是沒有YearLocator的運氣。這裏是我寫的代碼:使用matplotlib設置x軸的最小/最大年份
fig=pyplot.figure()
ax=fig.gca()
ax.plot_date(days,nee,'r-',label='model daily nee')
ax.plot_date(days,nee_obs,'b-',label='obs daily nee')
# locate the ticks
ax.xaxis.set_major_locator(YearLocator())
# format the ticks
ax.xaxis.set_major_formatter(DateFormatter('%Y'))
# set years 1992-2007
datemin = datetime.date(1992, 1, 1)
datemax = datetime.date(2007, 12, 31)
ax.set_xlim(datemin, datemax)
labels=ax.get_xticklabels()
setp(labels,'rotation',45,fontsize=10)
legend(loc="upper right", bbox_to_anchor=[0.98, 0.98],
ncol=1, shadow=True)
pyplot.ylabel('NEE($gC m^{-2} day^{-1}$)')
pyplot.title('Net Ecosystem Exchange')
pyplot.savefig('nee_obs_model_HF_daily.pdf')
# rotates and right aligns the x labels, and moves the bottom of the
# axes up to make room for them
#fig.autofmt_xdate()
pyplot.show()
pyplot.close()
你的天'數組是如何構建的? – 2012-02-29 15:47:03
你能否提供'days','nee'和'nee_obs'的一些樣本數據。請同時發佈您的導入信息,以便我不必查找'YearLocator'和'DateFormatter'來自'matplotlib.dates',並且我可以在'pyplot'中找到'setp'和'legend'。 – BioGeek 2012-02-29 15:53:15