简体   繁体   中英

Using matplotlib how could I plot a histogram with given data in python

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.

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: 在此处输入图片说明 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, ...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM