3
$\begingroup$

I have two discrete functions, which I'll greatly simplify for this question:

RedFnc[i_, j_] := 1 + i + j;
BlueFnc[i_, j_] := 1 + (1 - i) + (1 - j);

I am interested in plotting the min:

MinFnc[i_, j_] := Min[RedFnc[i, j], BlueFnc[i, j]];
DiscretePlot3D[ 
 MinFnc[i, j], {i, 0, 1}, {j, 0, 1},
 ExtentSize -> Full]


      Discrete
What I want to do is color the square-top Red if it is the RedFnc that determines the min, and Blue if it is the BlueFnc that determines the min. So the box in the front-left corner, over {0,0,0}, would have a Red top because $1 < 3$.

I cannot see how to accomplish this. So I need to color the tops of the cells according to a certain pattern determined by the min. It would be easier if I wanted to color according to the max, as then I could just Show[] both and the higher one would be visible.

I'd appreciate any ideas.


Postscript. Here's what I produced with the help of MichaelE2 and kglr:


          BGR
          (Green: ties between Blue & Red functions.)


$\endgroup$
  • $\begingroup$ Thanks to both @MichaelE2 and @ kglr with functionally equivalent answers. Had to chose one. $\endgroup$ – Joseph O'Rourke Mar 20 at 21:22
3
$\begingroup$
DiscretePlot3D[MinFnc[i, j], {i, 0, 1}, {j, 0, 1}, 
 ExtentSize -> Full, 
 ColorFunction -> (If[RedFnc[#, #2] < BlueFnc[#, #2], Red, Blue] &),
 ColorFunctionScaling -> False]

enter image description here

With ColorFunction -> (If[RedFnc[#, #2] <= BlueFnc[#, #2], Red, Blue] &) we get

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Nice! May I ask what does ColorFunctionScaling->False do? $\endgroup$ – Joseph O'Rourke Mar 20 at 20:47
  • 3
    $\begingroup$ @Joseph, with default setting ColorFunctionScaling->True the arguments to the color function are scaled: "Scaling is done so as to make the minimum and maximum values of all variables lie between 0 and 1. " With ColorFunctionScaling->False "original unscaled values are fed to the color function." $\endgroup$ – kglr Mar 20 at 20:57
3
$\begingroup$

Perhaps this?

MinFnc[i_, j_] := Min[RedFnc[i, j], BlueFnc[i, j]];
DiscretePlot3D[MinFnc[i, j], {i, 0, 1}, {j, 0, 1}, ExtentSize -> Full,
  ColorFunction -> 
  Function[{i, j, z}, If[z == RedFnc[i, j], Red, Blue]], 
 ColorFunctionScaling -> False]

enter image description here

It reevaluates RedFnc[i, j], which is just a minor irritation unless RedFnc is very slow.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Ah, didn't realize ColorFunction was that versatile. $\endgroup$ – Joseph O'Rourke Mar 20 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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