# ColorFunction uses graphics coordinates instead of Plot3D coordinates

I've had the same effect in Mathematica 9 and 10.

I'm trying to color a 3D Plot with another function, let's call it colorFun ( it should highlight the areas where the colorFun is above a certain threshold), but ColorFunction seems to use the wrong coordinates.

Horribly colored minimal example

colorFun := Function[{x, y},If[x < y, Red, Blue]]
Plot3D[Evaluate[x^2+y^2],{x,0,1},{y,0,2},ColorFunction->colorFun]


Note that x and y have different intervals plotted, so the divide should not be through the middle. Similar things happen if you change the colorFun to something like y<0.5 . It seems that the ColorFunction is not using the same coordinates as the function, but rather a kind of normalized version, always going from 0 to 1.

Is this a bug, or is Mathematica beating my ability to understand computers again?

• You actually essentially answered your own questions: the values passed to ColorFunction are in fact scaled to [0,1] by default. To avoid that, use ColorFunctionScaling -> False. – MarcoB Jul 15 '15 at 14:57
• Possible duplicates: (6741), (6986), (14758) – Mr.Wizard Jul 15 '15 at 15:05
• Please pardon the reopen but I was just about to post an answer when it closed. If you would still like to close this as a duplicate let me know. Either way I hope my answer is useful to you. – Mr.Wizard Jul 15 '15 at 15:20
• I'm fine with keeping it open, if others agree to my impression that your answer help show a new facet of the problem, as compared to the old answers. – GeckoGeorge Jul 15 '15 at 15:36

You'll get a much crisper output if you use Mesh functionality instead:

Plot3D[x^2 + y^2, {x, 0, 1}, {y, 0, 2},
MeshFunctions -> {#/#2 &},
Mesh -> {{1}},
]


Plot3D[x^2 + y^2, {x, 0, 1}, {y, 0, 2},
MeshFunctions -> {#/#2 &, # &, #2 &},
Mesh -> {{1}, 12, 12},
]


• It does look a lot better. Thanks for teaching cool new stuff! – GeckoGeorge Jul 15 '15 at 15:34

And immediately after submitting, I find the answer here:

Using ColorFunctionScaling->False

Plot3D[Evaluate[x^2+y^2],{x,0,1},{y,0,2},ColorFunction->colorFun,ColorFunctionScaling->False]


Gives the correct coloring. Sorry to bother you all, and thanks for listening!

Decided to keep the question and answer it myself for other who might do the same searches I did, since finding the answer was kinda random for me.