1
$\begingroup$

I want to colour a 3D plot according to it's value. I could only mange in one direction (say in 'z' direction) but I want to show them in all direction together. I have written the following code:

cf = ColorData["Rainbow"];
plot = SphericalPlot3D[
  1/((Sin[\[Theta]]^4*
       Cos[\[Phi]]^4*0.049896792) + (2*(Sin[\[Theta]]*
         Cos[\[Phi]])^2*(Sin[\[Theta]]*
         Sin[\[Phi]])^2*(-0.01555592)) + (2*(Sin[\[Theta]]*
         Cos[\[Phi]])^2*(Cos[\[Theta]])^2*(-0.030833372)) + (Sin[\
\[Theta]]^4*
       Sin[\[Phi]]^4*0.011343866) + (2*(Sin[\[Theta]]*
         Sin[\[Phi]])^2*(Cos[\[Theta]])^2*(0.007005355)) + (Cos[\
\[Theta]]^4*0.025839216) + ((Sin[\[Theta]]*
         Sin[\[Phi]])^2*(Cos[\[Theta]])^2*(0.01848854)) + ((Sin[\
\[Theta]]*
         Cos[\[Phi]])^2*(Cos[\[Theta]])^2*(0.020627753)) + ((Sin[\
\[Theta]]*Cos[\[Phi]])^2*(Sin[\[Theta]]*
         Sin[\[Phi]])^2*(0.031580823))), {\[Theta], 
   0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, 
  ColorFunction -> (cf@Rescale[#3, {0, 100}] &), Axes -> True, 
  ColorFunctionScaling -> False]

And here is the output I got:

enter image description here

I am using Mathematica 8 version and my desire output would be something like (forget about the shape, picture is just for understanding. I want the color description) shown below:

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Try ColorFunction -> (ColorData["Rainbow", #6] &) (without the ColorFunctionScaling setting). This is in the docs... $\endgroup$ – J. M. will be back soon May 23 '16 at 15:57
  • $\begingroup$ @J.M.: Nice!! I couldn't think about this smart way. Thank you! $\endgroup$ – baban May 23 '16 at 16:04
3
$\begingroup$

The ColorFunction for SphericalPlot3D takes 6 arguments, referring to the Cartesian and spherical coordinates.

cf = ColorData["Rainbow"];
plot = SphericalPlot3D[
    1/((Sin[θ]^4*
         Cos[ϕ]^4*0.049896792) + (2*(Sin[θ]*
            Cos[ϕ])^2*(Sin[θ]*
            Sin[ϕ])^2*(-0.01555592)) + (2*(Sin[θ]*
            Cos[ϕ])^2*(Cos[θ])^2*(-0.030833372)) + (Sin[θ]^4*
         Sin[ϕ]^4*0.011343866) + (2*(Sin[θ]*
            Sin[ϕ])^2*(Cos[θ])^2*(0.007005355)) + (Cos[θ]^4*0.025839216) + ((Sin[θ]*
            Sin[ϕ])^2*(Cos[θ])^2*(0.01848854)) + ((Sin[θ]*
            Cos[ϕ])^2*(Cos[θ])^2*(0.020627753)) + ((Sin[θ]*Cos[ϕ])^2*(Sin[θ]*
            Sin[ϕ])^2*(0.031580823))), 
    {θ, 0, π}, {ϕ, 0, 2 π}, 
    ColorFunction -> Function[{x, y, z, θ, ϕ, r}, cf@#], 
    Axes -> True] & /@ {x, y, z, θ, ϕ, r}

enter image description here

I think you want the last one, scaling by r.

$\endgroup$
  • $\begingroup$ Jason, I edited your text as it implied that ColorFunction only took one argument. $\endgroup$ – rcollyer May 23 '16 at 15:58
  • $\begingroup$ @JasonB: Thank you so much for your quick reply. Yes, you got the right one. $\endgroup$ – baban May 23 '16 at 16:02
  • $\begingroup$ @rcollyer Thanks for clarifying the post, I do get a bit sloppy at the end of the workday $\endgroup$ – Jason B. May 23 '16 at 17:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.