Plotting's issue that cannot explain
이전 댓글 표시
Hello everyone,
I got a trouble with plot3 and surf.
I plot a surface and 2 lines on the surface. Everything is okay until this weird happening. In my code, if I change the option of line's style is solid for red one, the line will disappear. But if I change it into 'x' or '+', then it works. The problem just affects on the red one but not the pink one. I cannot explain why.
I am looking forward to hearing from you.
Thank you in advance.
close all; clc; clear
alpha = 5.5;
[y,x] = meshgrid(-50:0.1:50);
r=(y.^3 - 3*y.^2 + y + 3);
s=-(x.^3 - 3*x.^2 + x + 3);
Pnpo = 3*x.*x.*y - x.*y + 2*y + x - 7;
Pnpor = 3*r.*r.*y - r.*y + 2*y + r - 7;
Pnpos = 3*x.*x.*s - x.*s + 2*s + x - 7;
m = surf(y,x,Pnpo,'FaceAlpha',0.7);
m.EdgeColor = 'none';
xlim([-50 50])
ylim([-50 50])
zlim([-6000 6000])
xlabel('y')
ylabel('x')
zlabel('z')
hold on
plot3(s,x,Pnpos,'-m','LineWidth',2) % pink line
hold on
%plot3(y,r,Pnpor,'-r','LineWidth',2); % red line ---> the line disappears
plot3(y,r,Pnpor,'+r','LineWidth',2); % red line ---> the line appears
댓글 수: 2
채택된 답변
추가 답변 (1개)
Ameer Hamza
2020년 3월 6일
In your code y, r, and pnpor are 2D matrices with dimensions 1001x1001. line3 function is creating 1001 lines, and each individual line is so small that it is invisible. Following will fix this issue
plot3(s(:),x(:),Pnpos(:),'-m','LineWidth',2) % pink line
% hold on
p = plot3(y(:),r(:),Pnpor(:),'-r','LineWidth',2); % red line ---> the line disappears
댓글 수: 3
Walter Roberson
2020년 3월 6일
Using (:) will join the parts incorrectly.
The lines are not drawn too small to be invisible: the LineWidth would ensure that they were drawn at constant number of screen pixels no matter what the zoom level was. The lines really are not drawn at all. See my Answer for the reason.
Nuec Tah
2020년 3월 6일
Ameer Hamza
2020년 3월 7일
The reasoning in Walter's answer is correct. The corresponding columns of y, r, and Pnpos are mapping to a single point in the 3D graph, and there is no line at all. With this context, the most efficient solution will be
plot3(y(1,:),r(1,:),Pnpor(1,:),'-r','LineWidth',2);
카테고리
도움말 센터 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!