# How to visualize four-dimensional data? [duplicate]

I have following data that I made up for this purpose. In data, let's say first three column is coordinate of center of balls and fourth column is the value I want to plot such that min of fourth column is blue and max of fourth column is red and the rest is between using TemperatureMap. I know I may use ArrayPlot only for fourth column after partitioning. Or I may use ListDensityPlot3D. Another word why there is no ArrayPlot3D (instead of square cuboid may be used) in Mathematica? Any suggestion? Thanks.

data = Append[#, RandomReal[{0, 10}]] & /@ (Append[#, 0] & /@Tuples[Range[1, 6], 2])
Graphics3D[Sphere[#, 0.2] & /@ data[[All, 1 ;; 3]], Axes -> True]

• Have you seen ListDensityPlot3D[]? – J. M.'s ennui Apr 2 '17 at 14:19
• Also, checking out Image3D could be worthwhile. – kirma Apr 2 '17 at 14:22
• @J.M. Yes, I have seen it but it interpolates the data and there is no IntepolationOrder->0 option for that function. – OkkesDulgerci Apr 2 '17 at 14:22
• @kirma I looked up Image3D sorry but that's not what I want. ListDensityPlot3D[] is the closest one but still not exactly. – OkkesDulgerci Apr 2 '17 at 14:31
• Have you seen BubbleChart3D ? – Simon Woods Apr 2 '17 at 15:30

**EDIT:** Corrected to use "TemperatureMap" rather than "Rainbow"

SeedRandom[1]

data = Append[#, RandomReal[{0, 10}]] & /@
(Append[#, 0] & /@
Tuples[Range[1, 6], 2]);

{min, max} = MinMax[data[[All, 4]]]

(*  {0.118355, 9.77172}  *)

Legended[
Graphics3D[{
ColorData["TemperatureMap"][Rescale[Last[#], {min, max}]],
Sphere[Most[#], 0.2]} & /@ data,
Axes -> True,
ImageSize -> Large],
BarLegend[{"TemperatureMap", {min, max}}]]


EDIT 2: Using BubbleChart3D as suggested by Simon Woods

Legended[
BubbleChart3D[data,
ColorFunction -> Function[{x, y, z, r},
ColorData["TemperatureMap"][r]]],
BarLegend[{"TemperatureMap", {min, max}}]]


EDIT 3: Custom color function

cf = (Blend[{
{min, RGBColor[0, 0, 1]},
{min + 1/3 (max - min), RGBColor[0, 1, 0]},
{min + 2/3 (max - min), RGBColor[1, 1, 0]},
{max, RGBColor[1, 0, 0]}}, #] &);

Legended[Graphics3D[{cf[Last[#]], Sphere[Most[#], 0.2]} & /@ data,
Axes -> True, ImageSize -> Large], BarLegend[{cf, {min, max}}]]


Legended[BubbleChart3D[data, ColorFunction -> Function[{x, y, z, r}, cf[r]],
ColorFunctionScaling -> False], BarLegend[{cf, {min, max}}]]


• @andre - corrected. Thanks. – Bob Hanlon Apr 2 '17 at 15:15
• You can get the ColorFunction to do the rescaling for you. From the docs: ColorData[{"gradient",{min,max}}] gives a color gradient that ranges from min to max. – Simon Woods Apr 2 '17 at 15:29
• Thank you all for your help. I have one more question. Can we use ColorFunction -> (Blend[{RGBColor[0, 0, 1], RGBColor[0, 1, 0], RGBColor[1, 1, 0], RGBColor[1, 0, 0]}, #] &) instead of "TemperatureMap". I want to replace white color with green one. Any suggestion? – OkkesDulgerci Apr 11 '17 at 1:47
• @OkkesDulgerci - see edit. This is described in documentation. – Bob Hanlon Apr 11 '17 at 2:29
• Sorry, I guess I commented for wrong figure, I would like to use Graphics3D – OkkesDulgerci Apr 11 '17 at 2:38