2017-04-16 3 views
0

以下は、二項分布乱数に関するプログラムです。このコードでは、私は文hx,xedge = np.histogram(x,xgrid)を理解していません。'hx、xedge = np.histogram(x、xgrid)'の意味

どうしますか?棒グラフの描画にはヒストグラムが使用されていますか?

私はこのコードで折れ線グラフを作る:

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib 
matplotlib.rc('xtick', labelsize=12) 
matplotlib.rc('ytick', labelsize=12) 
#generate random number from binomial density 
# with test number of 10 and probability of event of 0.4 
x = np.random.binomial(10,0.4,size=1000) 
print(x) 
#analyze the random samples with a histogram 
xgrid = np.arange(0.5,20.5,1) 
xcenter = (xgrid[1:]+xgrid[0:len(xgrid)-1])/2. 
hx,xedge = np.histogram(x,xgrid) 
#draw the histogram 
fig = plt.figure(figsize=[10,5]) 
ax = fig.add_subplot(111) 
ax.plot(xcenter,hx,'ko-') 
fig.savefig('binomrand_hist.png',bbox_inches='tight') 

答えて

0

あなたがdocumentation for numpy.histogramを見ていましたか?

この関数は、(ここでx)いくつかのデータをとり、そしてビンの配列(ここでxgrid)、タプル(hx,xedge)として各ビン内の観察の数、並びに各ビンのエッジの値を返します。

ax.plot(xcenter,hx,'ko-') 
+0

どうもありがとう:

その後、スクリプトがラインを使用して、(xcenterとして計算)各ビンの中心位置対観測(hx)の数をプロットします。私はドキュメントを知っています。あなたの答えは私をより明確にします。 –