Histogram per hour - matplotlib

后端 未结 1 1943
闹比i
闹比i 2021-01-14 15:50

I\'m analyzing public data on transport accidents in the UK.

My dataframe looks like this :

Index     Time

0         02:30
1         00:37
2                 


        
相关标签:
1条回答
  • 2021-01-14 16:26

    What you are missing is setting the format of the matplotlib x-axis format:

    df.set_index('hour', drop=False, inplace=True)
    df = df['hour'].groupby(pd.Grouper(freq='60Min')).count()
    ax = df.plot(kind='bar', color='b')
    ticklabels = df.index.strftime('%H:%Mh')
    ax.xaxis.set_major_formatter(matplotlib.ticker.FixedFormatter(ticklabels))
    plt.show()
    
    0 讨论(0)
提交回复
热议问题