# ColorData does not read functions? [on hold]

I'm new to the community and to Mathematica, but I looked around a bit and I couldn't find a solution to my problem, so I thought I'd ask. Inspired by Density plot on the surface of sphere, I wanted to to draw a density plot on a sphere. The code

SphericalPlot3D[1, {θ, 0, π}, {Φ, 0, 2 π},
ColorFunction ->
Function[{θ},
ColorData["TemperatureMap"][Exp[-(θ)^2*100]]],
ColorFunctionScaling -> True, Mesh -> False, Boxed -> False,
Axes -> False, SphericalRegion -> True, ViewAngle -> .3]


Yields more or less what I want:

The problem is that I wanted to pick a ColorFunction defined elsewhere in the code. Something like:

g[θ_] := Exp[-(θ)^2*100]

SphericalPlot3D[1, {θ, 0, π}, {Φ, 0, 2 π},
ColorFunction ->
Function[{θ}, ColorData["TemperatureMap"][g[θ]]],
ColorFunctionScaling -> True, Mesh -> False, Boxed -> False,
Axes -> False, SphericalRegion -> True, ViewAngle -> .3]


I just define the Gaussian somewhere else and then plug it in. This still does the job.

However, the concrete reason why I embarked into this is that I would like to have an animation for the dispersion of heat on a sphere. First I'd solve the heat equation numerically:

g[t_, θ_] :=
Evaluate[f[t, θ] /.
NDSolve[{-Tan[θ] D[f[t, θ], θ] +
D[D[f[t, θ], θ], θ] -
D[f[t, θ], t] == 0,
f[0, θ] == Exp[-(θ)^2*100]},
f, {t, 0, 100}, {θ, -Pi/2, Pi/2}]]


And then animate the thing above:

Animate[SphericalPlot3D[1, {θ, 0, π}, {Φ, 0, 2 π},
ColorFunction ->
Function[{θ},
ColorData["TemperatureMap"][g[t,θ]],
ColorFunctionScaling -> True, Mesh -> False, Boxed -> False,
Axes -> False, SphericalRegion -> True, ViewAngle -> .3],{t,0,1}]


However, if I try to plot it at t=0, things already don't work:

SphericalPlot3D[1, {θ, 0, π}, {Φ, 0, 2 π},
ColorFunction ->
Function[{θ},
ColorData["TemperatureMap"][g[0,θ]],
ColorFunctionScaling -> True, Mesh -> False, Boxed -> False,
Axes -> False, SphericalRegion -> True, ViewAngle -> .3]


I don't understand what's the difference with the other case. Is there any basic mechanism I'm missing? Thanks in advance.

Edit: maybe it's important to add that the code works if I use Hue instead of some ColorData option. If I insert

Hue[g[t, θ]]


ColorData["TemperatureMap"][h[t,θ]]


everything works. But I would like to have TemperatureMap.

New contributor
nelv is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

## put on hold as off-topic by Jason B., eyorble, bbgodfrey, Johu, m_goldbergyesterday

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Jason B., eyorble, bbgodfrey, Johu, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

• If you evaluate g[0,0], for example, you get {1.}. The argument to ColorData should be a real value between 0 and 1, not a list. Try First[g[t, theta]]. – C. E. Dec 6 at 19:50
• Or better to include the First in the definition of g. – KraZug Dec 6 at 20:16