I'm not sure why
SphericalPlot3D[1, {θ, 0, π}, {ϕ, 0, 2 π},
ColorFunction ->
Function[{θ, ϕ},
ColorData["Rainbow"][
Re[SphericalHarmonicY[5, 2, θ, ϕ]]]],
ColorFunctionScaling -> False]
looks different to
SphericalPlot3D[1, {θ, 0, π}, {ϕ, 0, 2 π},
ColorFunction -> (ColorData["Rainbow"][
Re[SphericalHarmonicY[5, 2, #4, #5]]] &),
ColorFunctionScaling -> False]
(I don't understand how the # symbols work here.) Which one is correct for plotting this spherical harmonic? But my main question is why do the plots not show the full Rainbow color palette? I would like to plot this spherical harmonic using the full Rainbow color palette from min to max value.
Any help would be greatly appreciated!
UPDATE:
The first question has now been answered. Thank you to all who contributed :-) Here is a simple example to expose my confusion about the color palette (my unanswered question):
SphericalPlot3D[1, {\[Theta], 0, \[Pi]}, {\[Phi], 0, 2 \[Pi]},
ColorFunction -> (ColorData["Rainbow"][
Re[SphericalHarmonicY[5, 2, #4, #5]]] &),
ColorFunctionScaling -> False]
BarLegend[{ColorData[
"Rainbow"], {MinValue[{ComplexExpand[
Re[SphericalHarmonicY[5,
2, \[Theta], \[Phi]]]], {0 <= \[Theta] < \[Pi],
0 <= \[Phi] < 2 \[Pi]}}, {\[Theta], \[Phi]}],
MaxValue[{ComplexExpand[
Re[SphericalHarmonicY[5,
2, \[Theta], \[Phi]]]], {0 <= \[Theta] < \[Pi],
0 <= \[Phi] < 2 \[Pi]}}, {\[Theta], \[Phi]}] }},
LegendLayout -> "Row"] // Quiet
BarLegend[{"Rainbow", {MinValue[{ComplexExpand[
Re[SphericalHarmonicY[5,
2, \[Theta], \[Phi]]]], {0 <= \[Theta] < \[Pi],
0 <= \[Phi] < 2 \[Pi]}}, {\[Theta], \[Phi]}],
MaxValue[{ComplexExpand[
Re[SphericalHarmonicY[5,
2, \[Theta], \[Phi]]]], {0 <= \[Theta] < \[Pi],
0 <= \[Phi] < 2 \[Pi]}}, {\[Theta], \[Phi]}] }},
LegendLayout -> "Row"] // Quiet
In this example, I suspect that the color function is scaling from 0 to 1 (the first legend), whereas I want the color function to scale from min to max of whatever I'm plotting (the second legend). How do I achieve this?
x
andy
) irrespective of what name you call them. Consequently, your first plot is equivalent toSphericalPlot3D[1, {θ, 0, π}, {ϕ, 0, 2 π}, ColorFunction -> (ColorData["Rainbow"][ Re[SphericalHarmonicY[5, 2, #1, #2]]] &), ColorFunctionScaling -> False]
$\endgroup$