2

here is the data:

111, 3  
122, 4  
155, 3  
192, 5  
11,  9  
123, 10  
120, 23

now how could I able to plot a histogram using this two set of data in matplotlib. please help.

1 Answer 1

13

You can create a barchart like this:

from matplotlib.pyplot import *
x = [111,122,155,192,11,123,120,]
y = [3,4,3,5,9,10,23]
bar(x,y)
show()

gives: enter image description here Using hist() bins your data for you, so you would pass it your raw data, ie. it would look like this:

data = [111, 111, 111, 122, 122, 122, 122, 155, ...]
Sign up to request clarification or add additional context in comments.

3 Comments

@abhisek - The above plot is a histogram.
i dont need any info about bar diagram. Please give me the codes for histogram only.
@abhisek - In an histogram the area of the bar is equal to the frequency of that data. It can be drawn as a barchart. Your data (appears to, although your question is unclear) contains frequency infomation, so the easiest way to plot it as a histogram is to do the above. I also explain that if your data is raw, you can use hist() and it will generate the histogram for you.

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.