3d plot plotting in 2d and 2d plot plotting in 3d.
122 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Eamon Gekakis
on 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
0 Comments
Star Strider
on 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.
.
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!