关于python中plt.hist参数的使用详解
如下所示:
matplotlib.pyplot.hist( x,bins=10,range=None,normed=False, weights=None,cumulative=False,bottom=None, histtype=u'bar',align=u'mid',orientation=u'vertical', rwidth=None,log=False,color=None,label=None,stacked=False, hold=None,**kwargs)
x:(n,)arrayorsequenceof(n,)arrays
这个参数是指定每个bin(箱子)分布的数据,对应x轴
bins:integerorarray_like,optional
这个参数指定bin(箱子)的个数,也就是总共有几条条状图
normed:boolean,optional
IfTrue,thefirstelementofthereturntuplewillbethecountsnormalizedtoformaprobabilitydensity,i.e.,n/(len(x)`dbin)
这个参数指定密度,也就是每个条状图的占比例比,默认为1
color:colororarray_likeofcolorsorNone,optional
这个指定条状图的颜色
我们绘制一个10000个数据的分布条状图,共50份,以统计10000分的分布情况
"""
Demoofthehistogram(hist)functionwithafewfeatures.
Inadditiontothebasichistogram,thisdemoshowsafewoptionalfeatures:
*Settingthenumberofdatabins
*The``normed``flag,whichnormalizesbinheightssothattheintegralof
thehistogramis1.Theresultinghistogramisaprobabilitydensity.
*Settingthefacecolorofthebars
*Settingtheopacity(alphavalue).
"""
importnumpyasnp
importmatplotlib.mlabasmlab
importmatplotlib.pyplotasplt
#exampledata
mu=100#meanofdistribution
sigma=15#standarddeviationofdistribution
x=mu+sigma*np.random.randn(10000)
num_bins=50
#thehistogramofthedata
n,bins,patches=plt.hist(x,num_bins,normed=1,facecolor='blue',alpha=0.5)
#adda'bestfit'line
y=mlab.normpdf(bins,mu,sigma)
plt.plot(bins,y,'r--')
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title(r'HistogramofIQ:$\mu=100$,$\sigma=15$')
#Tweakspacingtopreventclippingofylabel
plt.subplots_adjust(left=0.15)
plt.show()
以上这篇关于python中plt.hist参数的使用详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。