Copy/save image functions stop UIAxes graph from automatically resizing

2 vues (au cours des 30 derniers jours)
Derek Wolfe
Derek Wolfe le 27 Juil 2021
Commenté : Derek Wolfe le 25 Août 2025
I'm seeing an issue with automatic resizing in an appdesigner UIAxes object. Normally the graph will shrink to accomodate a legend and expand when a legend is deleted. But using the built in "Save As" or "Copy as Image" functions on the graph break this resizing behavior and lock the graph at the current size. The copygraphics() function causes the same issue
For example, if I add plots and create a legend the graph will automatically resize so the legend fits within the same window
Empty UIAxes graph:
Plots added to graph, automatically resized for legend:
It's possible to go back and forth between these states until an image of the graph is copied or saved. That will lock the graph at the current size so it no longer expands when cleared
Copy or save image:
Broken, no longer resizes:

Réponse acceptée

Aashray
Aashray le 21 Août 2025
Luckily, I have R2021a installed in my old laptop and so I was able to reproduce the issue. Initially I saw it in App Designer, but then I tested with a plain “uifigure” + “uiaxes” (no App Designer) and was still able to reproduce the same behavior (after using Copy as Image or “copygraphics”, the axes stopped resizing automatically when the legend was added/removed).
When I tried the same script in the current release (R2025a), the problem never resurfaced, the axes continue to shrink/expand correctly with the legend even after copying or saving.
To me, this looks like a version specific issue and thus a simple MATLAB version upgrade would fix the issue.
I am attaching the script I used for reproducing the issue for reference:
%Run the script section by section.
% Try to clear the plot, re plot several times, and then use
% copygraphics, then try to clear plot, do the plot
% again, notice the uiaxes doesn't change its size automatically.
f = uifigure;
a = uiaxes(f);
%%
Xdata = 1:1:10;
Yseed = 0.1:0.1:1;
hold(a, 'on');
for (i=1:10)
Ydata = i * Yseed;
legendStr{i} = sprintf('Signal %d', i);
handles(i) = plot(a, Xdata, Ydata);
end
hold(a, 'off');
% create legend
leg = legend(handles, legendStr, 'Location', 'southoutside', 'Orientation', 'horizontal', 'NumColumns', 1);
%a.Toolbar.Visible = 'off';[AB1] [AG2]
%a.Toolbar.Visible = 'on';
%%
cla(a);
legend(a, 'off');[AB3]
I hope this helps!
  1 commentaire
Derek Wolfe
Derek Wolfe le 25 Août 2025
Thank you for taking the time to confirm this is fixed in the most recent release

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by