2
$\begingroup$

Mathematica misrepresents data with Histogram by choosing "arbitrary" range in its bins.

For example the command:

Histogram[Table[RandomReal[], {100000}]]

Gives the expected picture:

enter image description here

However, the command:

Histogram[Table[1.005 RandomReal[], {100000}]]

Gives the following:

enter image description here

As you can see the last bar is much shorter than the rest. This clearly happens because Mathematica rounds up severely the range of the values and the last bins falls mostly out of the range. Can Mathematica be convinced not to do that?

$\endgroup$
3
$\begingroup$

From details sections on bin specs, if you need n bins you can do

$$\{x_{min},x_{max}, (x_{max}-x_{min})/n \}$$

for instance in your case of 21 bins:

Histogram[RandomReal[1.005, 100000], {0, 1.005, 1.005/21}]

enter image description here

To make sure for sanity the right edge of the last bin is really where it should be you can zoom in on it:

Histogram[RandomReal[1.005,100000],{0,1.005,1.005/21},
PlotRange->{{.95,1.05},Automatic}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.