# Controlling spacing of histograms in Histogram3D

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?

-

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]


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}}]


-
Wonderful! Thanks for the explanation of the meaning of {10,{1}}! – Joseph O'Rourke Apr 21 '14 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"}]


(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.)

-
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 '14 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 '14 at 9:48