How to preserve the 3d plot box, when changing patch visibility.
Afficher commentaires plus anciens
I have a 3d plot with a collection of patches. If I set a subset of patches Visible attributes to 'off', the plot box is recomputed. How can I capture and preserve all aspects of the plot box so that the visible patches don't jump around as other patches become visible or invisible.
Réponse acceptée
Plus de réponses (3)
Using axis() twice, we can both capture and reassert the axis limits,
axis(axis)
This also then converts all X,Y,ZLimModes to 'manual' so automatic changes will not happen.
4 commentaires
Borrowing your example,
figure;
ax = gca;
% drop some data between 1 and 5 in all 3 dimensions
for x = 1:4:5
for y = 1:4:5
line([x,x],[y,y],[1,5]);
end
end
axis equal;
view(ax,[1,1,1]);
originalLimits = axis %Check the current axis limits
axis(axis) %assert the limits and change to manual limit mode
isequal(originalLimits,axis) %recheck axis limits -- they're unchanged
ax.XLimMode %Verify manual mode
ax.YLimMode
ax.ZLimMode
John
le 13 Mar 2026 à 1:17
Voss
le 13 Mar 2026 à 1:58
"What does axis(axis) do?"
It's the same as
lim = axis();
axis(lim)
but without assigning to the variable lim.
Both of those usages are documented.
Matt J
le 13 Mar 2026 à 15:22
In matlab, it's some magic incantation whose semantics are completely independent of the rest of the language.
There must be dozens of other graphics commands that behave the same way:
xlim(xlim) %reasserts x-limits
ylim(ylim) %reasserts y-limits
zlim(zlim) %reasserts z-limits
campos(campos)
camva(camva)
camup(camup)
view(view)
figure(figure(n))
You don't need to capture anything.
To preserve the axes limits as they are, set the axes XLimMode, YLimMode, and ZLimMode to 'manual'. Obviously you would do that at a point in the code where the axes limits are what you want them to be, e.g., after all patches are initialized.
Other axes properties besides the limits affect the plot box, so you may want to set some other properties' modes to 'manual' as well in order to disable all undesired automatic changes to the plot box, e.g., PlotBoxAspectRatioMode, CameraViewAngleMode, etc. Look through the axes properties to see what you have control over:
5 commentaires
John
le 11 Mar 2026 à 22:08
Voss
le 12 Mar 2026 à 0:11
Interesting
Stephen23
le 12 Mar 2026 à 5:55
Report it as a bug with R2025x: https://www.mathworks.com/support/contact_us.html
If you set the modes all at once, i.e.,
set(ax,'XLimMode','manual','YLimMode','manual','ZLimMode','manual')
Then the limits don't change.
you may change patch color to fully transparent instead, e.g.
patch_handle.FaceAlpha = 0;
% or make use of the function
alpha(patch_handle, 'clear');
% prepend with "hold on;" if necessary
1 commentaire
John
le 18 Mar 2026 à 22:01
Catégories
En savoir plus sur Discrete Data Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


