Plot clean surface plots from scatter data
13 views (last 30 days)
Show older comments
I'm trying to make some nice 3D plots of some surfaces being generated by my MATLAB program. I can't use surf() because I'm working in spherical coordinates, and thus each data point must be preserved as a triplet of points as one can't just convert from spherical triplets to the rectangular (ix1) x vector, (jx1) y vector, (ixj) z matrix that surf requires. Simply doing a 3D scatter plot is messy looking. I'd like a surface.
Now, I have already used the method detailed here: http://www.mathworks.com/matlabcentral/fileexchange/5105
But I have two problems with it.
1) The figures are hideous. The surfaces I'm plotting resemble slices off of a sphere. Peel a piece of onion skin off and that may help visualize the thin, curved shape I'm trying to make. I believe what is happening is the routine is trying to connect the points on the empty edges together, making a solid, but that ruins the figure. I also think the process of converting from spherical to cartesian coordinates has left me with unevenly spaced points which throws off the size of the triangles, contributing to the messy look.
2) I'd like the surface to be a solid color. It looks confusing with a color gradient, like I'm trying to add in extra data and meaning to what is simply a figure of a shape.
Does anyone know of a different way to plot a surface in this manner, or even better, a way to get MATLAB to handle spherical coordinates so I can plot my data directly and skip this step?
2 Comments
Sean de Wolski
on 27 Jan 2012
Could you please post an image and/or sample set of data to a free webhosting site?
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Accepted Answer
Kelly Kearney
on 27 Jan 2012
I'm not quite clear on the format of your data to start, since you say you can't convert from spherical to cartesian in your case. Keep in mind that surf doesn't require a rectilinear grid, so if you have gridded data in spherical coordinates (assuming I understand your data description, if your triplets don't lie on a grid, you should be able to triagulate rho onto a uniform theta/phi grid), you can just translate and plot:
n = 20;
theta = (-n:2:n)/n*pi;
phi = (-n:2:n)'/n*pi/2;
[theta,phi] = meshgrid(theta,phi);
rho = rand(size(theta)) + 5;
[x,y,z] = sph2cart(theta, phi, rho);
surf(x,y,z, ones(size(x)))
3 Comments
Kelly Kearney
on 30 Jan 2012
Is r supposed to change between iterations of c? As typed above, you're just replotting the same surface on top of itself 10 times (though you change the color each time).
More Answers (0)
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!