3d plot plotting in 2d and 2d plot plotting in 3d.

80 次查看(过去 30 天)
Hello,
I am plotting both a 3d plot and 2d plot, using "plot3" to plot the 3d plot and "plot" to plot the 2d plot. When I do either or seperately, they plot fine. However, trying to plot them together in the same code results in the 3d plot being plotted in 2d, and the 2d plot being plotted in 3d.
The code is long, but the plotting sections are basically this (where x y z is one set of data, and a b is a different set of data):
figure(1)
hold on
plot3(x,y,z)
hold off
figure(2)
hold on
plot(a,b)
hold off

回答(2 个)

Eamon Gekakis
Eamon Gekakis 2022-6-24
Remove the holds from the code, you do not need to specify hold on/off if you are plotting two separate figures
figure(1)
plot3(x,y,z)
figure(2)
plot(a,b)
This may work better

Star Strider
Star Strider 2022-6-24
The must both plot in 3D, however the ‘z’ value of the 2D plot can be whatever you want (here, 10) —
x = 0:0.5:5;
y = 0:0.2:2;
z = x.^2 + y.^2;
a = x;
b = sqrt(x);
figure(1)
hold on
plot3(x,y,z, '-b')
% hold off
% figure(2)
hold on
plot3(a,b,zeros(size(a))+10,'-r')
hold off
view(30,30)
grid on
xlabel('(x),(a)')
ylabel('(y),(b)')
zlabel('z')
The zeros (constant) vector can be on any axis. I chose ‘z’ here.
.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by