pandas day of week axis labels

匿名 (未验证) 提交于 2019-12-03 02:16:02

问题:

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_index) 

Which displays 7 x-axis labels:

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

But I want:

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

What do I specify in code to change axis labels?

Thanks!

回答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]) 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!