2016-11-17 45 views
0

如果我有一個數據幀的大熊貓像這樣:我可以只有日期時間對象在刻度標籤matplotlib中的日期嗎?

     col1 col2 
time                   
2014-10-01 11:49:32 1  193.75 
2014-10-02 10:32:51 2  62.26 
2014-10-11 15:19:03 3  96.68 
...and so forth 

,並想繪製這些數值對於每一日期。

的情節中,得到的日期時間標籤,我會用

xticks2 = pd.date_range(start=df.iloc[0,0],end=df.iloc[-1,0], freq='7D', normalize=True)  
ax2 = axes2.xaxis.set_minor_locator(mpl.dates.WeekdayLocator(byweekday=range(7), interval=1)) 
ax2 = plt.xticks(xticks2,xticks2, rotation=0) 

但這給人的窘況長標籤,即2014-10-01十一時49分32秒。有沒有辦法像2014-10-01(日期沒有時間)一樣實現標籤?

回答

1

嘗試創建一個僅用於日期和情節的新列。

df['Dates'] = df.time.apply(lambda x: x.date().isoformat()) 
0

嘗試添加到您現有的代碼

axes2.xaxis.set_minor_formatter(mpl.dates.DateFormatter('%Y-%m-%d'))
+0

沒有做任何事情:( – durbachit

相關問題