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!

 Réponse acceptée

Star Strider
Star Strider le 6 Nov 2023

0 votes

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 commentaires

Panagiotis Artemiou
Panagiotis Artemiou le 7 Nov 2023
Thanks for the answer,
This is an nice approach, but I actually want the graph to be like the one I attached, meaning that the axes are on the center of the curves.
I do not know if we can have a graph like that in matlab.
Star Strider
Star Strider le 7 Nov 2023
My pleasure.
The orange curve could be shifted a bit so that it would be symmetrical about zero, however the blue curve is symmetrical about its axis.
This is the only way I can think of to get the sort of plot you want (I did several experiments).
Since this does not do what you want, I will delete my Answer in a few hours.
Panagiotis Artemiou
Panagiotis Artemiou le 7 Nov 2023
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:
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.
.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by