plot histogram of datetime.time python / matplotlib

穿精又带淫゛_ 提交于 2019-12-28 13:25:52

问题


I am trying to plot a histogram of datetime.time values. Where these values are discretized into five minute slices. The data looks like this, in a list:

['17:15:00', '18:20:00', '17:15:00', '13:10:00', '17:45:00', '18:20:00']

I would like to plot a histogram, or some form of distribution graph so that the number of occurrences of each time can be examined easily.

NB. Given each time is discretised then. The maximum number of bins in a histogram would be 288 = (60 / 5 * 24)

I have looked at matplotlib.pyplot.hist. But is requires some sort of continuous scalar


回答1:


I did what David Zwicker said and used seconds, and then changed the x axis. I will look at what Dave said about 'bins'. This works roughly and gives a bar per hour plot to start with.

def chart(occurance_list):
    hour_list = [t.hour for t in occurance_list]
    print hour_list
    numbers=[x for x in xrange(0,24)]
    labels=map(lambda x: str(x), numbers)
    plt.xticks(numbers, labels)
    plt.xlim(0,24)
    plt.hist(hour_list)
    plt.show()




回答2:


you have to convert the data in two variable and then you can use plotlab to plot in histograms.



来源:https://stackoverflow.com/questions/8369584/plot-histogram-of-datetime-time-python-matplotlib

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