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

111 Ansichten (letzte 30 Tage)
Thomas Watson
Thomas Watson am 24 Jun. 2022
Beantwortet: Star Strider am 24 Jun. 2022
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

Antworten (2)

Eamon Gekakis
Eamon Gekakis am 24 Jun. 2022
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 am 24 Jun. 2022
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.
.

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by