3D plot two curves
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Panagiotis Artemiou
el 6 de Nov. de 2023
Comentada: Star Strider
el 7 de Nov. de 2023
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 comentarios
Respuesta aceptada
Star Strider
el 6 de Nov. de 2023
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 comentarios
Star Strider
el 7 de Nov. de 2023
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.
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!