# Normalized histogram (density) in pgfplots [closed]

I have a data file containing 100 256 values ranging from 0.01 to 3, approximately. I would like to plot the density of this data set. I have the theoretical (asyptotic distribution) drawn for reference. I'm trying to use the [hist=density] option, but it doesn't seem to normalize correctly.

WE:

\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}


This gives me

As you see I have 12 bins, over a range of 3, so each bar is 0.25 units wide. All of the bars are lower than 0.2, so my area is for sure smaller than 12 * 0.25 * 0.2 = 0.6.

The histogram should be normalized so the area is 1 for it to be considered a density, so am I missing something?

(I could normalize the histogram using octave, and then simply give this histogram to pgfplots to plot normally, but it seems like the hist=density option should do that automatically)

Any ideas?

## closed as off-topic by Stefan Pinnow, Torbjørn T., CarLaTeX, ebosi, MicoFeb 20 '17 at 14:17

• This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• This might be a bug. Could you add the content of eval.dat to your question so I can test this? – Jake Mar 8 '16 at 10:35
• Thanks for adding the data. I edited your question to include the data inline, that way people don't have to download a separate file. I hope you don't mind. I tested this with PGFPlots 1.12 (overleaf.com/4551738btdxhp#/13699235) and it works correctly. Are you perhaps using an old version of PGFPlots? – Jake Mar 8 '16 at 11:12
• @Jake I'm using (from the .log) pgfplots 2013/10/03 v1.9 Data Visualization (1.9). Seeing as your example gets the job done, I guess it is just a matter of me getting the new version. Thanks for all your help! – Vanligvodka Mar 8 '16 at 11:49
• @Jake Yes, everything works after updating to 1.12. Thanks for everything. I can't seem to find where to close the question tho... – Vanligvodka Mar 18 '16 at 16:45
• I'm voting to close this question because updating PGFPlots solved the problem. – Stefan Pinnow Feb 20 '17 at 13:36