1
$\begingroup$

The following code:

repeat[m_, n_Integer?Positive] := Sequence @@ ConstantArray[m, n]
data = {repeat[71, 2], repeat[73, 3], repeat[74, 5], 76, repeat[77, 3], 78, 80}
Histogram[data, {2}, "Probability"]

Produces the following histogram:

Histogram

Since the least data point is 71 and the bin width is 2, the first bin, unsurprisingly, starts at 70. Keeping the bin width at 2, how can I force it to start at 70.5?

$\endgroup$
3
  • 1
    $\begingroup$ If you look at the Details section of the Histogram documentation, you'll find that you can give a bin specification as {xmin, xmax, dx}, so in your case perhaps Histogram[data, {70.5, 82, 2}, "Probability"]? $\endgroup$
    – MarcoB
    Commented Apr 18, 2021 at 19:35
  • 1
    $\begingroup$ @MarcoB Thank you, Histogram[data, {70.5, 80.5, 2}, "Probability"] did the trick. For reference, I used 80.5 because the largest value in the dataset (80) is in the [78.5, 80.5] bin. Do you want to post that as an answer for me to accept? $\endgroup$
    – Lucca
    Commented Apr 18, 2021 at 20:24
  • $\begingroup$ Lucca, I'm glad it helped. I'd recommend that you post a self-answer with that information and the extra modification you made to suit your dataset. Self-answers are encouraged here! $\endgroup$
    – MarcoB
    Commented Apr 18, 2021 at 21:25

1 Answer 1

1
$\begingroup$

Histogram[data, {70.5, 80.5, 2}, "Probability"] did the trick. I used 80.5 because the largest value in the dataset (80) is in the [78.5, 80.5] bin.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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