gpt4 book ai didi

python - matplot python 直方图中缺少最后一个 bin

转载 作者:太空宇宙 更新时间:2023-11-03 16:11:12 25 4
gpt4 key购买 nike

我正在尝试根据我的值绘制直方图

x = ['3', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5',
'2', '3', '4', '5', '6', '4', '2', '0', '1', '9', '8',
'8', '8', '8', '8', '9', '3', '8', '0', '9', '5', '2',
'5', '7', '2', '0', '1', '0', '6', '5']
x_num = [int(i) for i in x]

key = '0123456789'
for i in key:
print(i," count =>",x.count(i))

plt.hist(x_num, bins=[0,1,2,3,4,5,6,7,8,9])

enter image description here

最后 2 个数字“8, 9”箱的分布计数应为 6 , 4但在直方图中,它将 8 和 9 组合起来并得到值 10,而不是将它们分开。 bin 总数应该是 10 => 但它只给了我 9 的图表..

我怎样才能将它们分开并打破 8 和 9 ?

最佳答案

import matplotlib.pyplot as plt


x = ['3', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5',
'2', '3', '4', '5', '6', '4', '2', '0', '1', '9', '8',
'8', '8', '8', '8', '9', '3', '8', '0', '9', '5', '2',
'5', '7', '2', '0', '1', '0', '6', '5']
x_num = [int(i) for i in x]

key = '0123456789'
for i in key:
print(i, " count =>", x.count(i))

plt.hist(x_num, bins=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10])
plt.show()

关于python - matplot python 直方图中缺少最后一个 bin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39297630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com