Plot clean surface plots from scatter data
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Sean de Wolski
2012-1-27
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
采纳的回答
Kelly Kearney
2012-1-27
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 个评论
Kelly Kearney
2012-1-30
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).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!