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

95 views (last 30 days)
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 Comments
Adam
Adam on 7 Mar 2018
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 on 7 Apr 2022
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.

Sign in to comment.

Answers (2)

Jan
Jan on 7 Mar 2018
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 Comments
Jan
Jan on 20 Mar 2019
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 on 20 Mar 2019
Thank you so much for the valuable informations. It is very clear now. :)

Sign in to comment.


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

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!