pgfplots 中的归一化直方图(密度)

pgfplots 中的归一化直方图(密度)

我有一个数据文件,其中包含100 256 个值,范围大约从 0.01 到 3。我想绘制此数据集的密度。我绘制了理论(渐近分布)以供参考。我尝试使用 [hist=density] 选项,但它似乎无法正确归一化。

我们:

\documentclass[]{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro\M{256}
\pgfmathsetmacro\T{512}
\pgfmathsetmacro\c{\M/\T}
\pgfmathsetmacro\a{ (1-sqrt{\c})^2 }
\pgfmathsetmacro\b{ (1+sqrt{\c})^2 }
\begin{axis}[]
\addplot [domain=\a:\b, samples=401]{ (1 / (2*pi*\c*x)) * sqrt{max(x-\a,0)} * sqrt{ max(\b-x,0)}};
\addplot [hist={density,bins=12,data min=0,data max=3}] table [y index=0] {
 2.84792527e+00
 2.79971300e+00
 2.75767416e+00
 2.70242300e+00
 2.63474982e+00
 2.59112703e+00
 2.58169006e+00
 2.55872660e+00
 2.50714780e+00
 2.47939450e+00
 2.45540054e+00
 2.44807366e+00
 2.39869010e+00
 2.38551068e+00
 2.36071654e+00
 2.32497123e+00
 2.29341151e+00
 2.20198818e+00
 2.26704476e+00
 2.24770329e+00
 2.23883343e+00
 2.17155548e+00
 2.14851869e+00
 2.12234916e+00
 2.11434171e+00
 2.10296781e+00
 2.08434324e+00
 2.06187359e+00
 2.04121062e+00
 2.02674162e+00
 2.00116870e+00
 1.97414690e+00
 1.86391772e+00
 1.95819315e+00
 1.87970695e+00
 1.90289119e+00
 1.91374844e+00
 1.93106762e+00
 1.93453101e+00
 1.84736272e+00
 1.83451621e+00
 1.81579733e+00
 1.79746771e+00
 1.77324373e+00
 1.77591396e+00
 1.75389693e+00
 1.73632737e+00
 1.71546129e+00
 1.70649338e+00
 1.70902234e+00
 1.67391959e+00
 1.65833738e+00
 1.64774043e+00
 1.63668526e+00
 1.61796348e+00
 1.56738001e+00
 1.60193044e+00
 1.57845268e+00
 1.59057702e+00
 1.55485577e+00
 1.47873974e+00
 1.49340294e+00
 1.50267231e+00
 1.53386269e+00
 1.51979168e+00
 1.52503667e+00
 1.39142933e+00
 1.40132624e+00
 1.45745146e+00
 1.42332545e+00
 1.43487108e+00
 1.44369011e+00
 1.37909372e+00
 1.36653525e+00
 1.36166819e+00
 1.31151678e+00
 1.34572767e+00
 1.33291913e+00
 1.32218248e+00
 1.30052933e+00
 1.29376312e+00
 1.24943283e+00
 1.25805378e+00
 1.26974936e+00
 1.27652793e+00
 1.24218264e+00
 1.23015005e+00
 1.22280541e+00
 1.21187412e+00
 1.19787246e+00
 1.18224724e+00
 1.19084037e+00
 1.17022557e+00
 9.35412607e-02
 1.01126689e-01
 1.05046944e-01
 1.14640343e+00
 1.14043759e+00
 1.12821814e+00
 1.12323195e+00
 1.10807967e+00
 1.10339326e+00
 1.09178614e+00
 1.10600437e-01
 1.17731747e-01
 1.24266049e-01
 1.27153618e-01
 1.30847665e-01
 1.34807606e-01
 1.08193357e+00
 1.07153220e+00
 1.06051855e+00
 1.03323835e+00
 1.04720251e+00
 1.02451344e+00
 1.38801514e-01
 1.44349972e-01
 1.47735282e-01
 1.52610351e-01
 1.58219230e-01
 1.59985173e-01
 1.66222439e-01
 1.69911973e-01
 1.01664939e+00
 1.00923683e+00
 1.00460464e+00
 9.88497443e-01
 9.92123832e-01
 9.82364322e-01
 9.71801376e-01
 9.57434308e-01
 9.38667240e-01
 9.29565397e-01
 9.48983040e-01
 9.18951540e-01
 9.13876580e-01
 1.75229379e-01
 1.81038000e-01
 1.82687431e-01
 1.85693748e-01
 9.00846949e-01
 8.94817920e-01
 8.86782414e-01
 8.72470822e-01
 8.65317436e-01
 8.60003967e-01
 1.90750406e-01
 1.93583505e-01
 1.99589582e-01
 2.03355998e-01
 2.08235131e-01
 2.04995761e-01
 8.54237972e-01
 8.38019062e-01
 8.30602872e-01
 8.25107075e-01
 8.22235928e-01
 8.11973258e-01
 8.06110049e-01
 7.82969173e-01
 7.94341980e-01
 2.17336532e-01
 2.22492951e-01
 2.29378688e-01
 2.31412052e-01
 2.37269579e-01
 2.44569780e-01
 2.47479574e-01
 7.69630529e-01
 7.90996270e-01
 2.54803964e-01
 7.42313790e-01
 7.65172955e-01
 7.54705998e-01
 7.56934758e-01
 7.30326874e-01
 7.13491444e-01
 2.57078873e-01
 2.61146223e-01
 2.63164382e-01
 2.69880427e-01
 2.71051599e-01
 7.25560296e-01
 7.05977400e-01
 6.72653509e-01
 6.61137426e-01
 6.53955772e-01
 6.97464788e-01
 6.85441160e-01
 6.87531104e-01
 6.94202771e-01
 2.78592672e-01
 2.74923086e-01
 2.84629896e-01
 2.89965333e-01
 2.99153394e-01
 3.02679471e-01
 3.08903091e-01
 3.16598056e-01
 3.19550433e-01
 6.45028317e-01
 6.39678575e-01
 6.30148206e-01
 3.26900436e-01
 3.33051638e-01
 3.40591869e-01
 3.47608462e-01
 6.18681609e-01
 5.94874880e-01
 6.04131709e-01
 6.15394881e-01
 6.09297544e-01
 6.24899639e-01
 5.85961018e-01
 5.82262352e-01
 5.63451820e-01
 5.69384105e-01
 3.37010860e-01
 3.55447439e-01
 3.63433252e-01
 3.68066820e-01
 3.71597992e-01
 3.50862089e-01
 3.80250912e-01
 3.89908305e-01
 3.93942564e-01
 4.11209197e-01
 4.00779182e-01
 5.73555187e-01
 4.33220043e-01
 4.05788444e-01
 4.49729506e-01
 5.50658052e-01
 5.24581614e-01
 5.28757940e-01
 5.09345085e-01
 5.06674917e-01
 4.54050375e-01
 4.66052390e-01
 4.72312620e-01
 4.81922511e-01
 3.30540618e-01
 5.55127447e-01
 3.84951530e-01
 5.40326182e-01
 5.31938577e-01
 4.26837646e-01
 4.39155048e-01
 4.23378545e-01
 4.24972665e-01
 4.98169056e-01
 4.94796789e-01
 4.58194651e-01
 4.78098490e-01
 4.90495477e-01
 5.44041046e-01
};
\end{axis}
\end{tikzpicture}
\end{document}

这让我

在此处输入图片描述

如您所见,我有 12 个箱子,范围为 3,因此每个条形的宽度为 0.25 个单位。所有条形的宽度都低于 0.2,所以我的面积肯定小于 12 * 0.25 * 0.2 = 0.6。

直方图应该被标准化,因此面积为 1 才能被视为密度,所以我遗漏了什么吗?

(我可以使用八度对直方图进行标准化,然后只需将此直方图提供给 pgfplots 进行正常绘图,但似乎 hist=density 选项应该自动执行此操作)

有任何想法吗?

相关内容