Suppressing Live Script plotting figure inline

21 ビュー (過去 30 日間)
Máté
Máté 2025 年 9 月 5 日
編集済み: Máté 2025 年 9 月 9 日
I am plotting a figure from a Live Script using the
set(gcf, 'Visible', 'on');
option to make it appear in a separate, external window.
However, a copy of the figure still appears inline the Live Script which I would like to avoid. The figure should only appear externally (i.e. in a separate window, which it already does), and not get created inline too.
I have tried the following, none of which worked:
  • Plotting the figure inside a separate .m function (being called from the Live Script)
  • Creating the figure with visibility 'off'
  • Forcing 'normal' window style when creating the figure, i.e. f = figure('WindowStyle','normal')
  • Creating and plotting into a uifigure (copy still shows up inline)
  • Saving the figure with its visibility turned 'off' and opening it again in a different instance of another Live Script. Upon opening, both the external and the inline figures are created.
EDIT: Example Live Script attached for reference.
  2 件のコメント
Matt J
Matt J 2025 年 9 月 5 日
I can't reproduce the problem. I suggest attaching the Live Script.
Máté
Máté 2025 年 9 月 5 日
編集済み: Máté 2025 年 9 月 5 日
Thanks, please find the script attached.

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

採用された回答

Máté
Máté 2025 年 9 月 9 日
編集済み: Máté 2025 年 9 月 9 日
MathWorks has kindly provided a working solution.
The Live Editor does not snapshot figures with the 'internal' property set to true. In addition, the plot has to target the axes of the figure specifically for the inline snapshot to be avoided (see example below).
Note, that this is an undocumented solution and may change with future MATLAB releases.
Verfified example implementation (checked on R2024a):
disp("Before plot");
f = figure('Internal',true); % suppresses inline figure
set(f,'Visible','on'); % creates external figure window
ax = axes(f); % targets axes of external window specifically
plot(ax, 1:10, rand(1,10), '.-');
grid(ax, 'on');
xlabel(ax, 'X [s]');
ylabel(ax, 'Y [y]');
title(ax, 'Random data');
disp("After plot"); % check Live Script output window for absent plot

その他の回答 (1 件)

Matt J
Matt J 2025 年 9 月 5 日
編集済み: Matt J 2025 年 9 月 5 日
I don't think it's possible. However, you could shrink down the side bar area of the livescript where the figures are displayed, so that they aren't so visible,
  4 件のコメント
Máté
Máté 2025 年 9 月 6 日
Thanks for the advice @Umar.
Would you be able to provide an short example of the "wrap plotting in a function without returning any outputs" approach?
I tried something resembling this, yet the inline figure was still created. Perhaps I missed something then.
Thank you!
Umar
Umar 2025 年 9 月 6 日
編集済み: Umar 2025 年 9 月 6 日

Hi @Mate,

You mentioned:

"Would you be able to provide a short example of the 'wrap plotting in a function without returning any outputs'? I tried something resembling this, yet the inline figure was still created. Perhaps I missed something then."

Wrapping plotting in a function without returning outputs reduces workspace clutter but does not prevent the Live Script from capturing the figure inline—this is by design.

Minimal example:

function externalPlot(x,y)
if nargin==1, y=x; x=1:numel(y); end
h = findobj('Type','figure','Name','External Figure');
if isempty(h) || ~isvalid(h)
  h = figure('Name','External 
  Figure','NumberTitle','off','WindowStyle','normal','Visible','on');
else
  figure(h); clf(h);
end
plot(h,x,y,'.-'); grid(h,'on'); xlabel('X [s]'); ylabel('Y [y]'); title('Random plot');
end

Call from the Live Script:

externalPlot(1:10, rand(1,10));

Caveat: inline figures will still appear.

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

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by