# Coloring DiscretePlot3D according to min

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] 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: (Green: ties between Blue & Red functions.)

• Thanks to both @MichaelE2 and @ kglr with functionally equivalent answers. Had to chose one. – Joseph O'Rourke Mar 20 '20 at 21:22

## 2 Answers

DiscretePlot3D[MinFnc[i, j], {i, 0, 1}, {j, 0, 1},
ExtentSize -> Full,
ColorFunction -> (If[RedFnc[#, #2] < BlueFnc[#, #2], Red, Blue] &),
ColorFunctionScaling -> False] With ColorFunction -> (If[RedFnc[#, #2] <= BlueFnc[#, #2], Red, Blue] &) we get • Nice! May I ask what does ColorFunctionScaling->False do? – Joseph O'Rourke Mar 20 '20 at 20:47
• @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." – kglr Mar 20 '20 at 20:57

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] It reevaluates RedFnc[i, j], which is just a minor irritation unless RedFnc is very slow.

• Ah, didn't realize ColorFunction was that versatile. – Joseph O'Rourke Mar 20 '20 at 20:47