2
$\begingroup$

I have two lists, which are pretty similar. They are given by:

list1=Flatten[Table[#[[1]], #[[2]]] & /@ {{1, 2},{2, 9},{3, 3},{4,73},{5, 38}}]
list2=Flatten[Table[#[[1]], #[[2]]] & /@ {{1, 2},{2, 10},{3, 8},{4,65},{5, 22}}]

ie. list1 is a list of 2 1's, 9 2's, 3 3's, etc.

If I plot a histogram of them next to each other they come out like this:

{Histogram[list1],Histogram[list2]}

enter image description here

And I can't figure out why the labelling is different. I would like to have all of my numbers in the centre of the column, so tried using the answer from this question. as so:

{Histogram[list1, 
  Ticks -> {{# + .5, #} & /@ HistogramList[list1][[1]], Automatic}], 
 Histogram[list2, 
  Ticks -> {{# + .5, #} & /@ HistogramList[list2][[1]], Automatic}]}

But that comes out like this:

enter image description here

Any idea what's going on?

$\endgroup$
1
  • 1
    $\begingroup$ The definitions for the lists can be shortened to list1 == Flatten[Table @@@ {{1, 2}, {2, 9}, {3, 3}, {4, 73}, {5, 38}}] and list2 = Flatten[Table @@@ {{1, 2}, {2, 10}, {3, 8}, {4, 65}, {5, 22}}] $\endgroup$
    – Bob Hanlon
    Commented Aug 10, 2020 at 22:59

1 Answer 1

2
$\begingroup$

enter image description here

This in Mac version 12.1.0.0 using the input provided.

$\endgroup$
6
  • $\begingroup$ I'm using 12.0.0.0. Could it be a version issue? $\endgroup$ Commented Aug 10, 2020 at 22:36
  • 2
    $\begingroup$ @JonathanShock Try {Histogram[list1, {1}], Histogram[list2, {1}]}. $\endgroup$ Commented Aug 10, 2020 at 22:37
  • $\begingroup$ @RohitNamjoshi that's it, thank you! $\endgroup$ Commented Aug 10, 2020 at 22:42
  • 1
    $\begingroup$ @JonathanShock I can reproduce the difference on 12.0.0.0. HistogramList, which is what Histogram uses to compute the bin delimiters and counts, generates different output on 12.0.0.0 for list1. Guess it is a bug that was fixed in 12.1.0.0. $\endgroup$ Commented Aug 11, 2020 at 0:52
  • 1
    $\begingroup$ Interesting that 12.0 and 12.1 are different. Good idea with the extra argument to Histogram. Scales look better same as with `{Histogram[list1, {1}, PlotRange -> {0, 70}], Histogram[list2, {1}, PlotRange -> {0, 70}]}' $\endgroup$ Commented Aug 11, 2020 at 1:11

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.