3D plot two curves

조회 수: 1 (최근 30일)
Panagiotis Artemiou
Panagiotis Artemiou 2023년 11월 6일
댓글: Star Strider 2023년 11월 7일
Hello,
I have two curves (two velocity profiles) and i want to plot them in a 3d plot like shown in the image.
In a 2D plot the curves look like this:
Each curve is a two column matrix, in the 1st column the values are than of the horizontal axis and on the 2nd column the values are that of the vertical (as shown in the second image). However the problem is that neither the first nor the second column of each curve matches the 1st or 2nd column of the other curve, and when trying to plot with a simple 3d plot the dimensions of the matrices are on the same.
How can I do a plot like the one shown in the first picture?
Thank you!

채택된 답변

Star Strider
Star Strider 2023년 11월 6일
Perhaps something like this —
p = linspace(-pi/2, pi/2, 50)+pi/2;
x1 = cos(p);
y1 = 1.01*sin(p);
x2 = cos(p);
y2 = 0.99*sin(p);
figure
plot(x1, y1)
hold on
plot(x2, y2)
hold off
grid
z1 = zeros(size(x1))-1E-6;
z2 = zeros(size(x2))-1E-6;
figure
hp31 = plot3(x1, z1, y1);
hold on
hp32 = plot3(z2, x2, y2);
hold off
grid on
view(-45, 45)
rotate([hp31 hp32], [1 0 0], 90)
.
  댓글 수: 4
Panagiotis Artemiou
Panagiotis Artemiou 2023년 11월 7일
Thank you,
No it was helpful and maybe will be halpful for another person in the forum, so you do not need to delete it.
This is actually the first step, I want now the axes to be intersecting at (0,0,0) (after the oragne curve is shifted a bit to be symmetrical at 0).
Something like that:
Star Strider
Star Strider 2023년 11월 7일
The XAxisLocation and YAxisLocation properties only apply to 2D views, according to the documentation. The best you can do in a 3D plot is to draw lines along the axes.
This is the best I can do to emulate your diagram —
p = linspace(-pi/2, pi/2, 50)+pi/2;
x1 = cos(p);
y1 = 1.01*sin(p);
x2 = cos(p);
y2 = 0.99*sin(p);
figure
plot(x1, y1)
hold on
plot(x2, y2)
hold off
grid
z1 = zeros(size(x1));
z2 = zeros(size(x2));
figure
hp31 = plot3(x1, z1, y1);
hold on
hp32 = plot3(z2, x2, y2);
zlim([-1 1])
plot3(xlim, [0 0], [0 0], '-k')
plot3([0 0], [-1 0], [0 0], '-k')
plot3([0 0], [0 0], zlim, '-k')
xt = xticks;
yt = linspace(-1, 0, numel(xt));
zt = linspace(min(zlim), max(zlim), numel(xt));
plot3([1;1]*xt, [zeros(size(yt));-ones(size(yt))*0.05], [1;1]*zeros(size(zt)), '-k')
plot3([zeros(size(xt));-ones(size(xt))*0.05], [1;1]*yt, [zeros(size(zt));-ones(size(zt))*0.05], '-k')
plot3([zeros(size(xt));-ones(size(xt))*0.05], [zeros(size(zt));-ones(size(zt))*0.05], [1;1]*zt, '-k')
text(xt, zeros(size(yt)), zeros(size(zt)), compose('%g',xt))
text(zeros(size(xt)), yt, zeros(size(zt)), compose('%g',yt))
text(zeros(size(xt)), zeros(size(yt)), zt, compose('%g',zt))
xlabel('X')
ylabel('Y')
zlabel('Z')
hold off
Ax = gca;
Ax.Visible = 0;
grid on
view(-45, 45)
rotate([hp31 hp32], [1 0 0], 90)
Experiment with the text arguments ('HorizontalAlignment' and others) to adjust the tick label locations, and the tick plot calls to get them as you want them.
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by