我正在策划一个跨越一周的熊猫系列。我的代码:
rng = pd.date_range('1/6/2014',periods=169,freq='H')
graph = pd.Series(shared_index, index=rng[:168])
graph.plot(shared_index)
显示7个x轴标签:
[2014年1月6日,07,08,09,10,11,12]
但我想:
[星期一,星期二,星期三,星期四,星期五,星期六,星期日]
我在代码中指定了什么来更改轴标签?
谢谢!
答案 0 :(得分:2)
也许您可以手动修复刻度标签:
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])