How do I modify the color map to be based on magnitude for a surface plotted in spherical coordinates

15 views (last 30 days)
I am plotting a spherical probability distribution function, and I would like for the color map to show the magnitude away from the origin, as opposed to the vertical position in Z. Is this possible with a built in function? I've looked at caxis, but I'm not quite sure how it could help me here.

Accepted Answer

Andrew Schmalzer
Andrew Schmalzer on 14 May 2014
So my solution was to take the magnitude and use that for the 'C' input for surf...
i.e. (psi2 defines the probability distribution function, and mag_R is my magnitude) R = psi2.*sin(theta); X = R.*cos(phi); Y = R.*sin(phi); Z = psi2.*cos(theta); mag_R=sqrt(X.^2+Y.^2+Z.^2);
I then used:
surf(X,Y,Z,mag_R,'EdgeColor','none','FaceColor','interp')
to create the surface I desired.
Thanks for spending your time writing that up for me Walter!

More Answers (1)

Walter Roberson
Walter Roberson on 14 May 2014
caxis is not relevant.
How are you doing the plotting? If you are using a surface construct such as surf(), or if you are using patch(), then when you allow the color data to be automatically created, it is always based on the Z value. But you can set the CData property to the magnitude away from the origin and use colormapping. Or you can set the CData property to contain RGB triples that give the color directly.
But, when you set the CData naively the result is probably not going to be what you want. My guess about what you are looking for would be that you are looking for something closer to texturemapping, which is something that can be applied to surface or patch objects. See http://www.mathworks.co.uk/matlabcentral/answers/91858-is-it-possible-to-perform-texture-mapping-within-matlab

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!