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
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
B K
B K 2012-1-27
Apologies, hopefully this clarifies the issue:
Image 1: Done with just a scatterplot, you can see the way the surface is supposed to look but it's not ideal:
http://imgur.com/edkTm,2AMvN#0
Image 2: What I have so far using the aforementioned link, with the "exterior points connecting" issue visible:
http://imgur.com/edkTm,2AMvN#1

请先登录,再进行评论。

采纳的回答

Kelly Kearney
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 个评论
B K
B K 2012-1-29
Thanks so much for that! Using meshgrid in that way solved my problem. If I may trouble you for one more thing, I am trying to plot multiple surfaces on a single plot so my user can see how the change in a variable in my code affects the plot shape. What I have now is basically:
figure(fignum)
res = 50;
theta = linspace(1.7, 2.6, res);
phi = linspace(-.1, 0.8, res);
[theta, phi] = meshgrid(theta, phi);
hold on
for c = 1:10
%Calculate r values based on model parameters
[x, y, z] = sph2cart(theta, phi, r);
surf(x,y,z,(ones(size(x))*c))
end
hold off
legend('1','2','3','4','5','6','7','8','9','10')
But all this does is give me the tenth shape, instead of plotting all 10 on the same figure. Any idea why this may be?
Kelly Kearney
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 CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by