Set default visibility of figures to 'on' not working!

조회 수: 97 (최근 30일)
Eric Chadwick
Eric Chadwick 2018년 2월 22일
댓글: Thiago Azevedo 2022년 4월 7일
Hello,
I am using set(0,'DefaultFigureVisible','off') to hide figures that are created during my script. I want to plot things afterwards and doing the obvious set(0,'DefaultFigureVisible','on') does not seem to do the trick. I cannot display any plots after my code runs. I've tried taking it out of the loop its in and the function, but nothing seems to work. I've seen this post: https://www.mathworks.com/matlabcentral/answers/223980-how-to-set-figure-plot-visibility-to-on-by-default, but the answers were not helpful. The one that suggests to use setpref could be helpful if someone could tell me how to just restore default settings, but that also seems like overkill.
Does anyone know how to set figure visibility to 'on' after setting it to 'off' previously?
Thanks,
Eric
  댓글 수: 2
Adam
Adam 2018년 3월 7일
Setting the Default property only affects figures created after that point.
To set visibility of existing ones just keep the figure handles for all the ones you create in an array and use
set( hFigs, 'Visible', 'on' )
where hFigs is your array of existing invisible figures.
Thiago Azevedo
Thiago Azevedo 2022년 4월 7일
I know I am replying almost four years later, but I will do so for those who are encountering the same problems I did: figures saved with the 'DefaultFigureVisible', 'off'.
To add on this answer, if you save the figure after the command set(0,'DefaultFigureVisible','off'), the figure is saved with this setting. So everytime you try to open a .fig file, it won't open unless you perform something like:
hFigs = openfig(figurepath);
set(hFigs,'Visible','on');
To avoid needing to do so, you might want to save the figure after setting it back 'on' with set(hFigs, 'Visible', 'on'), such that the 'Visible' property is kept as 'on' for that figure even after closing it and opening again in another session. Else, the saved figure will simply return to its then set default visibility status 'off' once it's closed.
Cheers.

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

답변 (2개)

Jan
Jan 2018년 3월 7일
It does work:
set(groot, 'DefaultFigureVisible', 'off')
figure('Name', 'not visible')
set(groot, 'DefaultFigureVisible', 'on')
figure('Name', 'visible')
Maybe you do something like this:
set(groot, 'DefaultFigureVisible', 'off')
figure(1)
set(groot, 'DefaultFigureVisible', 'on')
figure(1)
But then the second figure command does not open a new figure.
I cannot try this currently, so please run it and post, what you observe.
  댓글 수: 3
Jan
Jan 2019년 3월 20일
Since Matlab R2014a the new Graphics Engine "HG2" is used. With "HG1" the graphic handles have been doubles and 0 was the root object. In HG2 the handles are a specific class, which helps to avoid confusions with numbers. For backward compatibility accessing 0 as root object is still supported, but groot is smarter.
For Backward compatibility I include a folder in the path for old Matlab versions, which contain e.g. this function:
function H = groot
H = 0;
So I can use groot in all of my codes, even if they run under R2009b.
Luna
Luna 2019년 3월 20일
Thank you so much for the valuable informations. It is very clear now. :)

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


Anian Roppel
Anian Roppel 2018년 3월 7일
Close the invisible figures created in your script (close all) and use set(0,'DefaultFigureVisible','on')

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by