2

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]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
OkkesDulgerci
  • 10,716
  • 1
  • 19
  • 38

1 Answers1

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

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198