Copy/save image functions stop UIAxes graph from automatically resizing

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:

 채택된 답변

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

Thank you for taking the time to confirm this is fixed in the most recent release

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 7월 27일

댓글:

2025년 8월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by