2
$\begingroup$

This question already has an answer here:

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]
$\endgroup$

marked as duplicate by István Zachar, MarcoB, happy fish, Wjx, J. M. is away Apr 7 '17 at 4:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

$\endgroup$
  • $\begingroup$ @andre - corrected. Thanks. $\endgroup$ – Bob Hanlon Apr 2 '17 at 15:15
  • 2
    $\begingroup$ 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. $\endgroup$ – Simon Woods Apr 2 '17 at 15:29
  • $\begingroup$ 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? $\endgroup$ – OkkesDulgerci Apr 11 '17 at 1:47
  • $\begingroup$ @OkkesDulgerci - see edit. This is described in documentation. $\endgroup$ – Bob Hanlon Apr 11 '17 at 2:29
  • $\begingroup$ Sorry, I guess I commented for wrong figure, I would like to use Graphics3D $\endgroup$ – OkkesDulgerci Apr 11 '17 at 2:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.