Disappear of z coordinate when plotting 3D
16 views (last 30 days)
Show older comments
Hi,
When I use figure and hold on with a for loop to plot a 3D plot, the z coordinate component always disappears which means the plot becomes 2D. Could anyone help the solve the issue? Thanks in advance. The folloing is the general code.
figure();
for index=1:max_val_1
other_code_here.....
for i=1:max_val_2
other_code_here.....
plot3(edge(i,1),edge(i,2),edge(i,3), 'o');
xlabel('x')
xlim([min max])
ylabel('y')
ylim([min max])
zlabel('z')
zlim([min max])
end
grid on
hold on
end
0 Comments
Answers (2)
the cyclist
on 10 Nov 2019
view(15,15)
after the plot is made.
I've seen a couple questions like this lately, so I'm wondering if there is some kind of bug with MATLAB defaulting to the "2-D" view (i.e. directly from "above", along the z-axis) when it should not be. I haven't been able to pin it down exactly enough for a bug report, though.
2 Comments
the cyclist
on 10 Nov 2019
I think you probably want the hold on statement immediately after the figure command (assuming your goal is to show every plot in that figure window). See the documentation for hold for the details.
Image Analyst
on 10 Nov 2019
Since you're plotting only a single point with each call to
plot3(edge(i,1),edge(i,2),edge(i,3), 'o');
you should place "hold on" inside that inner loop. And it should plot all max_val_2 points. Note that there is no reference to "index" inside your "i" loop so you should not expect anything different unless the badly-named "edge" vector changes within the outer "index" loop. By the way, edge(), min(), and max() are the names of a built-in functions so you don't want to use those as the names of your variable.
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!