Skip to content Skip to sidebar Skip to footer

Pandas Day Of Week Axis Labels

I am plotting a pandas series that spans one week. My code: rng = pd.date_range('1/6/2014',periods=169,freq='H') graph = pd.Series(shared_index, index=rng[:168]) graph.plot(shared

Solution 1:

perhaps you can manually fix the tick labels:

rng = pd.date_range('1/6/2014',periods=169,freq='H')
graph = pd.Series(np.random.randn(168), index=rng[:168])
ax = graph.plot()

weekday_map= {0:'MON', 1:'TUE', 2:'WED', 3:'THU',
              4:'FRI', 5:'SAT', 6:'SUN'}

xs = sorted(ax.get_xticks(minor='both'))
wd = graph.index[xs - xs[0]].map(pd.Timestamp.weekday)

ax.set_xticks(xs)
ax.set_xticks([], minor=True)
ax.set_xticklabels([weekday_map[d] for d in wd])

week-day

Post a Comment for "Pandas Day Of Week Axis Labels"