绘制datetime.time的直方图python/matplotlib [英] plot histogram of datetime.time python / matplotlib
问题描述
我正在尝试绘制datetime.time值的直方图.这些值离散为五分钟.数据如下所示:
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.每次给出都是离散的.直方图中的最大bin数为288 =(60/5 * 24)
NB. Given each time is discretised then. The maximum number of bins in a histogram would be 288 = (60 / 5 * 24)
我看过matplotlib.pyplot.hist.但是需要某种连续的标量
I have looked at matplotlib.pyplot.hist. But is requires some sort of continuous scalar
推荐答案
我按照David Zwicker所说的做了,用了几秒钟,然后改变了x轴.我将看看戴夫(Dave)关于垃圾桶"的看法.这项工作大致可行,并给出了每小时的柱线图.
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()
这篇关于绘制datetime.time的直方图python/matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!