I have a function with variables (theta,phi) the spherical coordinates.

I want to represent it as a density plot over the surface of a sphere.

following an answer to a previous question Density plot on the surface of sphere I have used the Texture[] directive, which allows one to wrap textures on surfaces. For this application, we can wrap the output of DensityPlot[] (after some postprocessing with Image[]) on a sphere. I use this approach as DensityPlot[] automatically scale the values.

So, I have this code:

Block[{ymap8, θ, ϕ}, ymap8 = Image[DensityPlot[
ocho[θ, ϕ] // Evaluate, {ϕ, 0, 2 π}, {θ, 0, π},
AspectRatio -> Automatic, ColorFunction -> jet, Frame -> False, ImagePadding -> None, 
PerformanceGoal -> "Quality", PlotPoints -> 200, PlotRange -> All,
 PlotRangePadding -> None], ImageResolution -> 144];

f8 = ParametricPlot3D[{Cos[ϕ] Sin[θ], 
Sin[ϕ] Sin[θ], Cos[θ]}, {ϕ, 0, 
2 π}, {θ, 0, π}, Lighting -> "Neutral", 
Mesh -> None, Boxed -> False, Axes -> False, 
PlotStyle -> Texture[ymap8], 
TextureCoordinateFunction -> ({#4, #5} &)]]

which produces a nice output: enter image description here

My question is, how can I do to add a bar legend which gives the information about what values the false color represents??



Edit: the function is:

0.114082 + 0.754845 Cos[θ]^4 - 0.417772 Cos[θ]^6 + 
0.114257 Cos[θ]^8 + 0.00117501 Cos[8 ϕ] Sin[θ]^8 +
Cos[θ]^2 (-0.417848 + 
0.195306 Cos[4 ϕ] Sin[θ]^4) + 
Cos[4 ϕ] (0.0331035 Sin[θ]^4 + 
0.00208865 Sin[2 θ]^4)
  • 1
    $\begingroup$ something like Legended[f8, BarLegend[{"Rainbow", {0, 5}}]] ? replace color function to your unknown jet $\endgroup$ – Harry Feb 16 '15 at 10:53
  • $\begingroup$ well, it seems to work with Rainbow but I like the jet colormap who resembles the mathematica vivid color. Why do you choose from 0 to 5, do you calculate the maximum and minimum of the function? $\endgroup$ – Popeye Feb 16 '15 at 11:06
  • $\begingroup$ No,to be clear:Legended[f8, BarLegend[{ColorData["Rainbow"][#/2] &, {0, 5}}]],replace the pure function ColorData["Rainbow"][#/2] & to your own color function. what is jet? $\endgroup$ – Harry Feb 16 '15 at 11:22
  • $\begingroup$ @user10712, here is an implementation of the jet color function from Matlab: stackoverflow.com/a/9321152 $\endgroup$ – MarcoB Mar 12 '16 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.