# Issues with ColorFunction

I have a function f[u,v] from $R^2 \to R$ that I want to use like coloring function over the surface:

sigma[u_,v_]:={Cos[u]*Cos[v],Sin[u]*Cos[v],Sin[v]^3}.


For that I've used the expression:

ParametricPlot3D[sigma[u, v], {u, 0, Pi}, {v, 0, 2*Pi}, Mesh -> None,
ColorFunction -> Function[{u, v}, ColorData["Rainbow"][f[u, v]]]]


where

 f[u_,v_]:=-((576 Cos[2 u])/(17 - 9 Cos[4 u])^2).


The result is:

which is not what I wanted.

I need that my coloring function evaluates colors in the coordinates position over the surfaces, depending from the sign of f[u,v] (for instance darker blue when f in strongly negative and a lighter color when f is strongly positive).

Thank you.

• Try ParametricPlot3D[sigma[u, v], {u, 0, Pi}, {v, 0, 2*Pi}, Mesh -> None, ColorFunction -> (ColorData["Rainbow"][#3] &)]. – IPoiler Jan 21 '16 at 18:13

In addition to the scaling issue, you need have your color function use the correct variables. To quote the documentation

The arguments supplied to functions in MeshFunctions and RegionFunction are x, y, z, u, and v. Functions in ColorFunction and TextureCoordinateFunction are by default supplied with scaled versions of these arguments.

This means that in order to use the parametric variables, u and v, as I believe you intend, you need to alter your function

Function[{x, y, z, u, v}, ColorData["Rainbow"][Rescale[f[u, v], {min, max}]]]


which gives

• Thank you for answering it works now😊 – Cesare Jan 22 '16 at 21:06

If you are going to use a custom color function you have to do the scaling of its values yourself. So you need to find the range of values of your color function, rescale its output value accordingly and tell ParametricPlot3D not to do scaling itself.

min = NMinValue[{f[u, v], 0 <= u <= Pi && 0 <= v <= 2 Pi}, {u, v}];
max = NMaxValue[{f[u, v], 0 <= u <= Pi && 0 <= v <= 2 Pi}, {u, v}];
ParametricPlot3D[sigma[u, v], {u, 0, Pi}, {v, 0, 2*Pi}, Mesh -> None,
ColorFunction ->
Function[{u, v}, ColorData["Rainbow"][Rescale[f[u, v], {min, max}]]],
ColorFunctionScaling -> False]


• Thank you for your answer ; actually i didn't express myself good, i want that in the point {u', v'}, the color of Sigma{u', v'} is given by f[u', v']. – Cesare Jan 22 '16 at 20:43
• Have a look at rcollyer's answer. I was assuming that you were referring to the x,y values since your f took only two arguments. – Sjoerd C. de Vries Jan 22 '16 at 20:52
• Yes, thank you again – Cesare Jan 22 '16 at 21:05