I am trying to rename my x labels with a text and wrote the following code:
dow=pd.to_datetime(df1['Dates']).dt.dayofweek
Weekdays= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
df2 = df1.groupby([dow,'Category'])['Category'].count().unstack('Category').fillna(0)
df2.plot(kind='bar', stacked=True,figsize=(12,6))
plt.xlabel("Day of week",fontsize=15)
plt.ylabel("Total Incidents",fontsize=15)
plt.xticks(dow,Weekdays)
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
However all the text is getting added on top of each other as below
Not sure what to fix in this?
Aucun commentaire:
Enregistrer un commentaire