使用matplotlib我如何在python中绘制具有给定数据的直方图 [英] Using matplotlib how could I plot a histogram with given data in python
本文介绍了使用matplotlib我如何在python中绘制具有给定数据的直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是数据:
111, 3
122, 4
155, 3
192, 5
11, 9
123, 10
120, 23
现在如何使用matplotlib
中的这两组数据绘制直方图.
请帮忙.
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()
给出:
使用hist()
为您分箱数据,这样您就可以将原始数据传递给它,即.看起来像这样:
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, ...]
这篇关于使用matplotlib我如何在python中绘制具有给定数据的直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文