简体   繁体   English

使用matplotlib如何在python中绘制具有给定数据的直方图

[英]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 . 现在我如何能够使用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. 使用hist()可以为您分箱数据,因此您可以将原始数据传递给它,即。 it would look like this: 它看起来像这样:

data = [111, 111, 111, 122, 122, 122, 122, 155, ...]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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