【发布时间】:2015-09-08 08:47:45
【问题描述】:
我有以下代码来绘制直方图。 time_new 中的值是发生某事的时间。
time_new=[9, 23, 19, 9, 1, 2, 19, 5, 4, 20, 23, 10, 20, 5, 21, 17, 4, 13, 8, 13, 6, 19, 9, 14, 9, 10, 23, 19, 23, 20, 19, 6, 5, 24, 20, 19, 15, 14, 19, 14, 15, 21]
hour_list = time_new
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)
pdb.set_trace()
plt.hist(hour_list,bins=24)
plt.show()
这会生成一个直方图,但是这些 bin 没有按照我的意愿对齐。我希望小时位于垃圾箱的中心,而不是边缘。
我提到了this question / answer,但它似乎也没有回答这个问题。
我为直方图尝试了以下代码,但它没有为值 23 绘制条形
plt.hist(hour_list, bins=np.arange(24)-0.5)
谁能帮我弄到 24 个箱子,每个箱子都以小时为中心?
【问题讨论】:
标签: python matplotlib histogram