I made a histogram of 1000 random coin tosses.How can I normalize the numbers in order to get the probabilities for each number. Basically, scaling the Y axis by a factor of 1/1000
The data are in the Table format.
As a summary, here are the different possibilities available to you.
As often in Mathematica, the easiest way is usually to use a built-in construct. As @Lukas mentioned in the comments, you can use the special height specification "Probability"
in Histogram[]
to get what you want.
data=Table[RandomInteger[],{1000}]
Histogram[data,Automatic,"Probability"]
But maybe, as @Jim Baldwin said, an alternative visualisation is best? Sometimes, you can't beat a simple table...
counts = Tally@Table[RandomInteger[], {1000}];
Grid[{Text /@ {"", "heads", "tails"},
Text /@ {"count", counts[[1, 2]], counts[[2, 2]]},
Text /@ {"probability", N[counts[[1, 2]]/1000],
N[counts[[2, 2]]/1000]}}, Frame -> All]
Strictly speaking however, you are asking to normalize the histogram scale. To do this, you need to define a custom height function as defined in the "Details and Options" section of the reference on Histogram
.
heightfunction[bins_, counts_] := counts/1000;
Histogram[Table[RandomInteger[], {1000}], {{0, 0.5, 1.1}}, heightfunction]
Note: I also adjusted the bins to remove the empty space on the left
Histogram[data,Automatic,"Probability"]
do what you want? $\endgroup$