Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have five histograms, hist1 = Histogram[data1, 20], to which I append {1, 2, 3, 4, 5} via Data1 = Map[{#, 1} &, hist1], and then plot


Histogram3D[{Data1, Data2, Data3, Data4, Data5}, 10, 
  ChartLegends -> Etc, Boxed -> False, 
  FaceGrids -> {Bottom, Front, Left}, ChartStyle -> "Pastel", 
  Ticks -> {Automatic, None, Automatic}, 
  AxesLabel -> {"x","y","z"}]

I cannot see how to control the width of the histograms (in the y-direction). Right now there is a gap between the 1st and the 2nd, etc. What control am I missing?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Here's some sample data along the lines of what I think you're using:

{data1, data2, data3, data4, data5} = 
    Table[{#, i} & /@ RandomVariate[NormalDistribution[i, i], 100], {i, 5}];

Now when we generate a 3D histogram with 10 bins, we get gaps:

Histogram3D[{data1, data2, data3, data4, data5}, 10]

enter image description here

The reason for this is that your bin specification, 10, gives ten bins in the $x$ direction, but also ten bins in the $y$ direction. Since you only have five datasets, half the bins in the $y$ direction are completely empty.

A solution is to use a bin specification that better accounts for how you are constructing your datasets. In this case, I like {10,{1}}, which uses ten bins in the $x$ direction, and unit-spaced bins in the $y$ direction:

Histogram3D[{data1, data2, data3, data4, data5}, {10, {1}}]

enter image description here

share|improve this answer
Wonderful! Thanks for the explanation of the meaning of {10,{1}}! –  Joseph O'Rourke Apr 21 at 11:37

Make the width 1:

f[{{xmin_, xmax_}, {ymin_, ymax_}, {zmin_, zmax_}}, ___] := 
  Cuboid[{xmin, ymin, zmin}, {xmax, ymin + 1, zmax}];
Histogram3D[N@{Data1, Data2, Data3, Data4, Data5}, 10, Boxed -> False,
  FaceGrids -> {Bottom, Front, Left}, ChartStyle -> "Pastel", 
 ChartElementFunction -> f, Ticks -> {Automatic, None, Automatic}, 
 AxesLabel -> {"x", "y", "z"}]

Mathematica graphics

(Update: Originally, I doubled both widths. Only one of the widths needed to be doubled, but setting it equal to 1 seemed much more natural.)

share|improve this answer
Great, Michael! Could I ask you to explain how you accomplished this? Is ChartElementFunction a Cuboid by default and you doubled it? –  Joseph O'Rourke Apr 21 at 1:16
@JosephO'Rourke I eye-balled the (yes, default) cuboid being about half-width. Then I tried doubling it, following an example in the docs. I suppose because I'm busy with work, the simpler method of setting the width to 1 didn't occur to me until I woke up this worning. –  Michael E2 Apr 21 at 9:48

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.