2017-02-09 204 views
0

在下面的表格中。情節,我想在x軸上繪製日期。我有日期的列表:matplotlib中x軸上的繪圖日期

import arrow as ar 
date_plt = '2016-04-01' 
_frst_day = '2016-01-01' 
_last_day = '2016-12-31' 
[ar.get(date_plt) + timedelta(days=x) for x in range((ar.get(_last_day) - ar.get(_frst_day)).days + 1)] 

我怎樣才能在x軸上繪製日期,同時仍然能夠利用的情節線和點(如圖所示)

enter image description here

+0

是什麼date_plt? – eyllanesc

+0

謝謝@eyllanesc,更新的問題 – user308827

回答

1

我想你想(有一些代碼來生成一個假的情節):

labels=[ar.get(date_plt) + timedelta(days=x) for x in range((ar.get(_last_day)-ar.get(_frst_day)).days + 1)] 
x=np.arange(366) 
y=x*10 
plt.plot([l.datetime for l in labels],y) #convert arrow in datetime 

注意,這樣做的方式datetime對象繪製,這是由autmatically處理MATP lotlib,例如在縮放和間距調整中(而不是例如在x,y上繪圖並更換刻度)。 要繪製或註釋你的數據,你可以直接尋址到datetime x軸,像(例如在150天):

plt.plot(labels[150].datetime,y[150],'o') 
plt.annotate('day 150',(labels[150].datetime,y[150]))