直方图绘制matplotlib

时间:2017-11-28 18:41:36

标签: python matplotlib plot bins

我有一个数字数组,我有一个数组,其中包含使用多少时间元素的数值。我必须创建直方图,显示使用数字列表中元素的次数。我知道直方图显示分布,但我没有得到结合的逻辑。

import sys, tkinter
import matplotlib.pyplot as plt

numbers=['23.7', '23.718', '23.73', '23.7225', '23.754', '23.76', '23.736', '23.745', '23.6','23.64','23.65','23.625','23.6166666666667','23.6666666666667', '23.575', '23.54', '23.525', '23.5', '23.445', '23.39', '23.37', '23.3733333333333', '23.3233333333333', '23.365', '23.29', '23.3066666666667', '23.272', '23.2', '23.23', '23.215', '23.14', '23.15', '23.18', '23.1166666666667', '23.1', '23.06', '23.02', '23.01', '23', '22.9816666666667', '22.945', '22.956', '22.9725', '22.912', '22.89', '22.865', '22.8733333333333', '22.815', '22.84', '22.79', '22.772', '22.76'']
how_many_times=[2, 1, 2, 2, 1, 3, 1, 2, 1, 1, 3, 1, 2, 1, 1, 1, 3, 1, 4, 2, 3, 1, 5, 1, 1, 1, 1, 10, 1, 1, 2, 1, 2, 1, 1, 19, 4, 2, 2, 2, 3, 1, 32, 2, 2, 6, 1, 2, 1, 1, 17, 3, 4, 6, 2, 3, 7, 44, 1, 5, 3,
 1, 6, 3, 2, 3, 3, 2, 56, 1, 7, 6, 1, 16, 6, 18, 3, 4, 75, 1, 7, 6, 10, 1, 3,]

numbers=[float(x) for x in numbers]
plt.hist(numbers,bins, histtype='bar',rwidth=0.08)
plt.xlabel('Numbers')
plt.legend()
plt.show()

此代码没有显示正确的分档和数字。我该如何解决这个问题?

0 个答案:

没有答案
相关问题