# Histogram and probability curve for a range of values

I don't know if I will be clear about what I am asking for, but here is my problem: how could I create a histogram (with the probability curve, later) when I have many different values (each one with frequency equals to one), in such a way that in the $$x$$ axis I put ranges (like: $$0$$ to $$80$$, $$80$$ to $$160$$, $$160$$ to $$240$$ and so on) and on the $$y$$ axis I have the frequency, that is the number of values that lie within the $$x$$ range?

To say, the list of my values is:

$$200,540,563,1031,458,957,200,800,226,314,517,210,900,160,432,380,89,1300,850,120,350,222,243,600,300,173,549,80,500,162,500,450,2000,300,647,371$$

I know I have to use BarChart. I just cannot get how to create a range on the $$x$$ axis and the frequency over $$y$$ axis.

Thank you!

• Histogram[data, {80}] where data is the list of values? Commented Apr 11, 2022 at 18:04

Get into the 21st century and use nonparametric density estimates. In other words, dump the histogram.

data = {200, 540, 563, 1031, 458, 957, 200, 800, 226, 314, 517, 210,
900, 160, 432, 380, 89, 1300, 850, 120, 350, 222, 243, 600, 300,
173, 549, 80, 500, 162, 500, 450, 2000, 300, 647, 371};
skd = SmoothKernelDistribution[data, "LeastSquaresCrossValidation",
{"Bounded", {0, \[Infinity]}, "Gaussian"}];
Plot[PDF[skd, x], {x, 0, Max[data]}]


And get the CDF:

Plot[CDF[skd, x], {x, 0, Max[data]}]


• Wondrous!! Thank you so much! Commented Apr 13, 2022 at 10:21
data = {200, 540, 563, 1031, 458, 957, 200, 800, 226, 314, 517, 210,
900, 160, 432, 380, 89, 1300, 850, 120, 350, 222, 243, 600, 300,
173, 549, 80, 500, 162, 500, 450, 2000, 300, 647, 371};
bins = Table[80 i, {i, 0, Max[data]/80 + 1}]

Histogram[data, {bins}]


Histogram[data, {bins}, "Probability"]


• Awesome! How to add the probability curve? Commented Apr 11, 2022 at 18:10
• Since the bins are of equal width Histogram[data, {80}] is sufficient. Commented Apr 11, 2022 at 18:11
• @xyzt You can count probabilities and these should sum up to one. probs = BinCounts[data, {bins}]/Length@data // N and Total@probs.
– Syed
Commented Apr 11, 2022 at 18:29
• @RohitNamjoshi I was trying a new syntax variation for bspec. Thanks for the heads up.
– Syed
Commented Apr 11, 2022 at 18:30