Plotting a color function on a sphere
7 views (last 30 days)
Show older comments
Dear kind helpers,
I have a question which I have not been able to resolve yet.
I have three vectors x, y and z with x(i), y(i) and z(i) giving a point on the unit sphere. I also have a fourth vector c of the same length as x,y and z containing function values, where c(i) corresponds to the function value at the point (x(i), y(i), z(i)) on the sphere.
I want to make a contour plot of the function c(i) on the sphere defined by all the points (x(i), y(i), z(i)). How can I do such a thing?
Best wishes,
Pablo
0 Comments
Answers (2)
Walter Roberson
on 19 Jun 2011
The following will not be a contour plot as such, but it might serve your purpose:
pointsize = 8;
scatter3(x,y,z,pointsize,c)
If you want something closer to a contour plot, you could use histc() or interp1() to effectively quantize the c values and pass the quantized values in to scatter3 instead of c itself.
Patrick Kalita
on 21 Jun 2011
There are a couple of avenues to explore. I wouldn't say either of them are particularly easy, unfortunately.
Idea 1: Use contourslice. The idea here would be that you'd first have to interpolate your scattered data c onto a uniform 3D grid (e.g. using meshgrid and TriScatteredInterp). Then you'd pass the gridded x, y, z, and c to contourslice along with 2D arrays Xi, Yi, Zi that define the surface of a sphere where the contours will lie.
Idea 2: Turn your x, y, and z data into spherical coordinates (using cart2sph). Then you can compute the contours in the 2D theta-phi space using contourc. The output of contourc will also be in terms of theta and phi. You can transform back into Cartesian coordinates with sph2cart (the radius being 1 at every point). Finally you can manually draw the contours with the resulting x, y, and z coordinates.
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!