Plotting's issue that cannot explain
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Más respuestas (1)
Ameer Hamza
el 6 de Mzo. de 2020
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 comentarios
Walter Roberson
el 6 de Mzo. de 2020
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
el 6 de Mzo. de 2020
Ameer Hamza
el 7 de Mzo. de 2020
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);
Categorías
Más información sobre Lighting, Transparency, and Shading en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!