Copy/save image functions stop UIAxes graph from automatically resizing
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Derek Wolfe
el 27 de Jul. de 2021
Comentada: Derek Wolfe
el 25 de Ag. de 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:

0 comentarios
Respuesta aceptada
Aashray
el 21 de Ag. de 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!
Más respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!