pandas day of week axis labels

后端 未结 1 1527

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=r         


        
相关标签:
1条回答
  • 2020-12-19 17:41

    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

    0 讨论(0)
提交回复
热议问题