Skip to content
Advertisement

How to replace pandas plot xticks with days?

I’ve got a pandas hist plot like shown below. As you can see the xticks are currently set to 0-6 (Sunday – Saturday). I’d like to replace the tick label to the actual days so the days are showing instead of numbers. 0 – Sunday 1 – Monday 2 – Tuesday 3 – Wednesday . .

ax_by_day = df['Day Of Week'].hist(bins=7, alpha=0.5, figsize=(10,6), edgecolor='black')
ax_by_day.set_xticks(list(range(0,7,1)))
ax_by_day.set_xlabel('Day')
ax_by_day.set_ylabel('No. of Processes Executed')

I believe there’s a way to map the xticks to new labels but surprisingly I’m unable to find details. Thanks in advance.

enter image description here

Advertisement

Answer

Using one of the many useful features of calendar:

import calendar
days = calendar.day_name
ax_by_day.set_xticklabels(days[6:] + days[:6])
Advertisement