我正在尝试根据我的价值来绘制自我图谱
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])
最后2个数字“8,9”bin的分配数应为6,4 但在直方图中,它将8和9组合在一起,得到10的值,而不是将它们分开。箱的总数应为10 =>但它只给了我9的图表。
我如何将它们分开并打破8和9?
答案 0 :(得分:1)
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()