Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this problem: I have three distributions and the relative histograms. But I would like to create an histogram in which the three columns of each single histogram for the same bin are put together (grouped) by the same x axis value. There is someone could help me?

share|improve this question
I tried also with BarChart but I wasn't able to put the three columns for each bin side by side. – Roryro87 Jun 28 '14 at 11:47
Can you explain why the obvious Histogram[{data1,data2,...}] is not good? – Szabolcs Jun 28 '14 at 13:56
It is not my choice unfortunately,but I needed to get the histograms more easily readable. – Roryro87 Jun 28 '14 at 14:48
It was not clear from your explanation that you wanted to have the bars next to each other instead of on top of each other. I did not understand the question until you commented on one of the answers. – Szabolcs Jun 28 '14 at 14:50
Sorry It wasn't easy to exaplain the problem but next time I will try to be more clear. – Roryro87 Jun 28 '14 at 14:54

Unlike BarChart (with its default ChartLayout option setting Grouped) Histogram does not accept Grouped as a ChartLayout option value. So, we need to transform the data to get the bin heights and use transformed data in BarChart:

d1 = RandomVariate[NormalDistribution[0, 1/2], 50];
d2 = RandomVariate[NormalDistribution[0, 1], 50];
d3 = RandomVariate[NormalDistribution[1, 1/2], 50]; 

BarChart[Transpose[(HistogramList[#, {-3, 4, 1}, "Count"] & /@ {d1, d2, d3})[[All, 2]]], 
 ChartStyle -> "Rainbow", ChartLabels -> {Range[-3, 4, 1], None}, 
 ChartLegends -> {"d1", "d2", "d3"}]

enter image description here

Update: Alternative layouts with the three histograms side-by-side:

BarChart[(HistogramList[#, {-3, 4, 1}, "Count"] & /@ {d1, d2, d3})[[All, 2]],
    ChartStyle -> {"Rainbow", None},
    ChartLabels -> {{"d1", "d2", "d3"}, Range[-3, 4, 1]},
    ChartLegends -> {{"d1", "d2", "d3"}, None},
    BarSpacing -> {None, Automatic}]

enter image description here

 BarChart[(HistogramList[#, {-3, 4, 1}, "Count"] & /@ {d1, d2,  d3})[[All, 2]],
   ChartStyle -> "Rainbow",
   ChartLabels -> {{"d1", "d2", "d3"}, Range[-3, 4, 1]},
   ChartLegends -> Range[-3, 4, 1],
   BarSpacing -> {None, Automatic}]

enter image description here

share|improve this answer
+1 (except that I get a different result at +2 and -3) – eldo Jun 28 '14 at 13:07
This is just what I mean, the only thing I did't need the Transpose command. Thank you :) – Roryro87 Jun 28 '14 at 14:46

You might also be interested in SmoothHistogram (new in v8).

d1 = RandomVariate[NormalDistribution[0, 1], 500];
d2 = RandomVariate[NormalDistribution[3, 1], 500];
d3 = RandomVariate[NormalDistribution[5, 1], 500];

SmoothHistogram[{d1, d2, d3},
 Axes -> False, Frame -> True,
 PlotLegends -> {"d1", "d2", "d3"},
 Filling -> Axis]

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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