Reduce lines shown in a surface plots

33 次查看(过去 30 天)
I followed a previous reply trying to reduce the number of lines on a 3D plot but it does not seem to work in my case. What is happening in my case is that it does not show any lines at all. I am not sure what am I doing wrong. Could you please help me?
The code that I am using is below, where PWNORM,PSNORM,DOS are the three vectors with data that define each point of my surface:
figure
surfc(PWNORM,PSNORM,DOS)%'FaceAlpha',0.5,(for transparency),'EdgeColor','none'
hidden on
colormap(flipud(colormap))
%colormap(flipud(hot))
caxis([20,70])
ylim([0 4]) %solar
xlim([0.5 5.5])%wind
zlim([20 70])
s=surfc(PWNORM,PSNORM,DOS,'EdgeColor','none')
%colormap(flipud(hot))
caxis([20,70])
ylim([0 4]) %solar
xlim([0.5 5.5])%wind
zlim([20 70])
xlabel('W ');
ylabel('S');
zlabel('SD');
%%Extract X,Y and Z data from surface plot
x=get(s,'XData');
y=get(s,'YData');
z=get(s,'ZData');
%%Create vectors out of surface's XData and YData
x=x(1,:);
y=y(:,1);
%%Divide the lengths by the number of lines needed
xnumlines = 50; % 10 lines
ynumlines = 50; % 10 partitions
xspacing = round(length(x)/xnumlines);
yspacing = round(length(y)/ynumlines);
%%Plot the mesh lines
% Plotting lines in the X-Z plane
hold on
for i = 1:yspacing:length(y)
Y1 = y(i)*ones(size(x)); % a constant vector
Z1 = z(i,:);
plot3(x,Y1,Z1,'-k');
end
% Plotting lines in the Y-Z plane
for i = 1:xspacing:length(x)
X2 = x(i)*ones(size(y)); % a constant vector
Z2 = z(:,i);
plot3(X2,y,Z2,'-k');
end
hold off

回答(2 个)

John BG
John BG 2017-8-7
编辑:John BG 2017-8-8
Hi Katerina
.
while
hs=surf(..)
hs
=
Surface with properties:
EdgeColor: 'none'
LineStyle: '-'
FaceColor: 'flat'
FaceLighting: 'flat'
FaceAlpha: 1
XData: [30×30 double]
YData: [30×30 double]
ZData: [30×30 double]
CData: [30×30 double]
returns a handle with the data you need to obtain x y z
hs=surfc(..)
only returns a handle to the surface contour, thus not valid to then get the sought x y z. Simply, x y z are not in hs out of surfc()
Use surf() instead
close all;clear all;clc
% hidden on
% colormap(flipud(colormap)) % or %colormap(flipud(hot))
% caxis([20,70])
% ylim([0 4]) %solar
% xlim([0.5 5.5])%wind
% zlim([20 70])
[PWNORM,PSNORM,DOS] = peaks(30)
hs=surf(PWNORM,PSNORM,DOS,'EdgeColor','none')
% or % surfc(PWNORM,PSNORM,DOS)%'FaceAlpha',0.5,(for transparency),'EdgeColor','none'
xlabel('W ');ylabel('S');zlabel('SD');
%%Extract X,Y and Z data from surface plot
x=get(hs,'XData');y=get(hs,'YData');z=get(hs,'ZData');
%%Create vectors out of surface's XData and YData
x=x(1,:);y=y(:,1);
%%Divide the lengths by the number of lines needed
xnumlines = 50; % 10 lines
ynumlines = 50; % 10 partitions
xspacing = round(length(x)/xnumlines);
yspacing = round(length(y)/ynumlines);
.
Now the lines plots
figure(2);hold all;
for i = 1:yspacing:length(y)
Y1 = y(i)*ones(size(x)); % a constant vector
Z1 = z(i,:);
plot3(x,Y1,Z1,'-k');
end
figure(3);hold all;
for i = 1:xspacing:length(x)
X2 = x(i)*ones(size(y)); % a constant vector
Z2 = z(:,i);
plot3(X2,y,Z2,'-k');
end
hold off
.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG
  2 个评论
Sonal Gupta
Sonal Gupta 2019-10-3
I copied your code exactly. However, I am getting the following two figures as Figure 2 and Figure 3 respectively. Figure 1 comes out as shown in your answer. What am I doing wrong?
Screenshot 2019-10-03 at 3.59.45 PM.png
Screenshot 2019-10-03 at 4.00.30 PM.png

请先登录,再进行评论。


Jan
Jan 2017-8-9
surfc replies the handle of the surface object and a list of handles to the patch objects. If you need the surface only, use this:
SurfcH = surfc(PWNORM, PSNORM, DOS, 'EdgeColor', 'none');
s = SurfcH(1);
I assume the rest of your code works directly then.

类别

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