# Problem with the BarChart3D function

I have a list of values {x,y,z} and I would like to create a 3D bar chart with axis x,y,z .

test= {{1, 1, 0.0425421}, {1, 2, 0.0603692}, {1, 3, 0.0659077}, {1, 4,
0.0631829}, {1, 5, 0.0520746}, {1, 6, 0.035611}, {1, 7,
0.0176222}, {1, 8, -0.00627115}, {1, 9, -0.0293295}, {1,
10, -0.0542067}, {2, 1, 0.0495183}, {2, 2, 0.0650703}, {2, 3,
0.0667629}, {2, 4, 0.0598549}, {2, 5, 0.0490927}, {2, 6,
0.0328169}, {2, 7, 0.0154528}, {2, 8, -0.00391657}, {2,
9, -0.0278968}, {2, 10, -0.0507444}, {3, 1, 0.0484558}, {3, 2,
0.0589233}}


I am struggling with the BarChart3D. I would like to have something like that :

http://blog.numerix.com/.a/6a011570f0b826970c016769008840970b-pi

Can someone help me ?

Thanks

There are several ways, I give it a try. One is to use ListPlot3D with option InterpolationOrder -> 0 and Filling -> Bottom. Here a slightly modified example from the documentation:

square[{{imin_, imax_}, {jmin_, jmax_}}] :=
Table[UnitStep[i - imin, imax - i] UnitStep[j - jmin, jmax - j], {i, 0, 20}, {j, 0, 20}]


and

ListPlot3D[
Abs@Fourier[square[{{2, 5}, {3, 7}}]],
Mesh -> None,
ColorFunction -> "Rainbow",
InterpolationOrder -> 0,
Filling -> Bottom
]


Or you can use DiscretePlot3D. You can use your data format but have to transform a bit. Here one way (optimized for reading), just extract the z-value and take (x,y) for the appropriate coordinates ("test" is your data):

func[i_, j_] := (Flatten @ Select[test, (#[[1]] == i && #[[2]] == j) &])[[3]]


and then:

DiscretePlot3D[
func[i, j], {i, 1, 2}, {j, 1, 8},
ExtentSize -> Full,
PlotTheme -> "Scientific",
ColorFunction -> "TemperatureMap"
]


Using BarChart3D

If you have to use BarChart3D you need to pre-process the input data to a form acceptable to BarChart3D, i.e., a list of lists of bar heights. Since your x and y values are integers you can get an array of bar heights using SparseArray:

barchrtdata = SparseArray[{#, #2} -> #3 & @@@ test, Automatic, Indeterminate];

BarChart3D[barchrtdata, ChartLayout -> "Grid", BarSpacing -> {.1, .2},
BoxRatios -> 1, ChartElementFunction -> "ProfileCube",
ChartStyle -> "Rainbow", BaseStyle -> Opacity[.5]]


Using BubbleChart3D

Alternatively, you can use BubbleChart3D using a ChartElementFunction that produces cuboids similar to BarChart3D:

bblchrtdata = {##, 1} & @@@ test;
BubbleChart3D[bblchrtdata, ChartStyle -> "Rainbow",
ChartElementFunction -> (ChartElementDataFunction[
"ProfileCube"][# /. {x_, y_, {z1_, z2_}} :> {x,
y, {0, (z1 + z2)/2}}, ##2] &), BubbleSizes -> {.05, .05}]


Using Graphics3D

grphcsdata = {{-.15, -.5, 0} + {1, 1, 0} {##}, {.15, .5, 0} + {##}} & @@@ test;

Graphics3D[{Opacity[.7],
ColorData[{"Rainbow", Through@{Min, Max}@test[[All, 3]]}][#[[2, 3]]],
ChartElementDataFunction["DoubleProfileCube"][Transpose[#], {}]} & /@ grphcsdata,
BoxRatios -> 1, Axes -> True]


• I haven´t had in mind BubbleChart3D... looks really good! Mar 22 '15 at 20:32