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?


2 Answers 2


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

  • $\begingroup$ Wonderful! Thanks for the explanation of the meaning of {10,{1}}! $\endgroup$ Apr 21, 2014 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.)

  • $\begingroup$ Great, Michael! Could I ask you to explain how you accomplished this? Is ChartElementFunction a Cuboid by default and you doubled it? $\endgroup$ Apr 21, 2014 at 1:16
  • $\begingroup$ @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. $\endgroup$
    – Michael E2
    Apr 21, 2014 at 9:48

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.