3D plot two curves
1 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Line Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!