JPC - 1 year ago 95
Python Question

# missing last bin in histogram plot from matplot python

I'm trying to draw histrogram based of my value

``````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])
``````

The last 2 numbers "8, 9" bin should have distribution count of 6 , 4
But in histogram it combine 8 and 9 and get value of 10 instead of separate them. Total number of bin should be 10 => but it only giving me graph of 9..

How could I separate them and break 8 and 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()
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download