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

南笙酒味 提交于 2019-12-08 12:52:54

问题


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:


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, ...]


来源:https://stackoverflow.com/questions/10512425/using-matplotlib-how-could-i-plot-a-histogram-with-given-data-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!