Pandas week label labels of the week

I am drawing 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_index)

      

Which displays the 7 x-axis labels:

[06 January 2014, 07, 08, 09, 10, 11, 12]

But I want:

[Mon, Tue, Wed, Thu, Fri, Sat, Sun]

What can I specify in the code to change the axis labels?

Thank!

+2


source to share


1 answer


maybe you can manually fix the tag 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

+2


source







All Articles