Copy/save image functions stop UIAxes graph from automatically resizing

2 ビュー (過去 30 日間)
Derek Wolfe
Derek Wolfe 2021 年 7 月 27 日
コメント済み: Derek Wolfe 2025 年 8 月 25 日
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:

採用された回答

Aashray
Aashray 2025 年 8 月 21 日
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 件のコメント
Derek Wolfe
Derek Wolfe 2025 年 8 月 25 日
Thank you for taking the time to confirm this is fixed in the most recent release

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by