以下是关于二项分布随机的程序。在这段代码中,我不明白句子hx, xedge </跨度> = np.histogram(x,xgrid)。
它有什么作用?直方图用于绘制条形图吗?
我 (0.5,20.5,1)xcenter =(xgrid [1:] + xgrid [0:len(xgrid)-1])/ 2。HX, xedge </跨度> = np.histogram(x,xgrid)
fig = plt.figure(figsize = [10,5])ax = fig.add_subplot(111)ax.plot(x中心,HX, ‘ko-’)fig.savefig( ‘binomrand_hist.png’,bbox_inches = ‘紧’)
你看看了吗? 文档 numpy.histogram ?
numpy.histogram
这个函数需要一些数据(这里 x )和一系列箱子(这里 xgrid ),并返回每个箱中的观察数量,以及每个箱子边缘的值作为元组 (hx,xedge) 。
x
xgrid
(hx,xedge)
后来,该剧本绘制了观察数量( hx )vs每个箱的中心位置(计算为 xcenter ),使用线:
hx
xcenter
ax.plot(xcenter,hx,'ko-')