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