# 3d Plot of (x,y,z) that looks like histogram3d

I'd like to create a 3d "bar plot" of data with three coordinates (xn,yn,zn). The Histogram3d function in Mathematica 11 looks great, but I just want to plot triplets, I don't want to count the number of ocurrances of anything. Is there some way to plot various heights associated with points in the (x,y) plane using this nice graphical style?

[(x1,y1,z1),
(x2,y2,z2),
...
(xn,yn,zn)]


• See here. Nov 27, 2016 at 15:26

If your data is regularly spaced you can use WeightedData with Histogram3D. If not you could create your own plot with Cuboid and Graphics3D.

First I'll create some regularly spaced triplet $\{x,y,z\}$ data in dat.

SeedRandom[12345];
With[{hl = HistogramList[RandomVariate[NormalDistribution[0, 1], {500, 2}]]},
{Flatten[Outer[List, Sequence @@ hl[[1, All, 2 ;;]]], 1],
Flatten@hl[[2]]}];
]
dat // Short

{{-3,-(5/2),0},{-3,-2,0},{-3,-(3/2),0},{-3,-1,0},{-3,-(1/2),0},{-3,0,1},
<<156>>,
{7/2,1/2,1},{7/2,1,0},{7/2,3/2,0},{7/2,2,0},{7/2,5/2,0},{7/2,3,0}}


# Regularly Spaced Data

With WeightedData each $\{x,y\}$ can be given a weight of $z$. Histogram3D understands this information. All that is needed is to specify bins that match the spacing of the data. In dat both $x$ and $y$ are spaced by $\frac{1}{2}$.

wdat = WeightedData[dat[[All, ;; -2]], dat[[All, -1]]];
Histogram3D[wdat, {{1/2}, {1/2}}]


# Triplets in General

For triplets in general you can create your own histogram-like plot using Cuboid and Graphics3D. Here a cuboid is created for each set by taking $\{x,y,0\}$ as the lower corner and $\{x+\Delta,y+\Delta,z\}$ as the upper corner. Deltas, colour, lighting, and the rest I leave to you.

Graphics3D[{Orange, Cuboid[{#1, #2, 0}, {#1 + .2, #2 + .2, #3}] & @@@ dat},
BoxRatios -> {1, 1, 1}, Axes -> True]


Hope this helps.