【问题标题】:pandas day of week axis labels熊猫星期轴标签
【发布时间】:2014-04-27 11:42:01
【问题描述】:

我正在策划一个为期一周的熊猫系列。我的代码:

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 轴标签:

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

但我想要:

[周一、周二、周三、周四、周五、周六、周日]

我在代码中指定什么来更改轴标签?

谢谢!

【问题讨论】:

    标签: python matplotlib pandas


    【解决方案1】:

    也许您可以手动修复刻度标签:

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

    【讨论】:

    猜你喜欢
    • 2016-04-10
    • 2017-08-07
    • 2019-10-01
    • 1970-01-01
    • 2018-04-11
    • 2018-12-17
    • 2017-06-05
    • 2017-01-31
    • 1970-01-01
    相关资源
    最近更新 更多