使用Python在数周内将第二个x轴添加到几个月中的x轴上

时间:2018-10-16 12:22:47

标签: python pandas matplotlib

我有一个图(starting point)在x轴上有星期数,我想在下面添加第二个x轴,该图显示相同的时间轴,但有几个月。

有任何提示吗?

# Organize data per week (based on the start time to know in which 
#  week it's that data entry)
df['Week']=df['Start Time'].dt.week

#Create DataFrame that show the duration of activities pro Category pro Week     
week_overview_h = df.groupby(['Week', 'Category'])[['Duration']].sum()

#Transform the type in the Duration column from time format to numbers:     
week_overview_h['Duration_h']= 
                   week_overview_h['Duration'].astype('timedelta64[h]')

#Create DataFrame that has all the categories as columns, the week as 
 rows, and the duration in h as values 
plot_week_overview_h = week_overview_h.unstack('Category').loc[:, 
                                                          'Duration_h']
#plot dataframe using bars and stacked 
fig=plot_week_overview_h.plot.bar(stacked=True)

#save the graph as png file
plt.savefig('graph_week_h.png')

0 个答案:

没有答案