1

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

enter image description here

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 ?

1
  • 1
    plt.hist(x_num, bins=[0,1,2,3,4,5,6,7,8,9, 10]) From the docs: The edges of the bins. Length nbins + 1 (nbins left edges and right edge of last bin) Commented Sep 2, 2016 at 17:14

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.