why are fig files opening invisible?

a few days ago matlab started opening figures from fig files with the Visible flag 'off'. After I figured what was happening it's just a matter of setting it to 'on' to see the figure, but why it suddenly started doing it? how do I revert to the normal behavior?

Answers (1)

There could be a few reasons why MATLAB started opening figures with the Visible property set to 'off' by default:
  1. You may have accidentally set the default figure Visible property to 'off'. This can be done via:
set(0,'DefaultFigureVisible','off')
To revert this, simply set it back to 'on':
set(0,'DefaultFigureVisible','on')
  1. If you are opening figures programmatically (e.g. with openfig), the Visible property defaults to 'off'. You need to explicitly set it to 'on':
h = openfig('figure.fig');
set(h,'Visible','on')
  1. You may have some startup code or script that is preemptively setting the DefaultFigureVisible to 'off'. Check your MATLAB startup folder and scripts.
  2. There could be an issue with your MATLAB installation or preferences where it is defaulting figures to invisible for some reason. Try resetting preferences or reinstalling as a last resort.

8 Comments

When you openfig(), the figure Visible property that is used is the one that was saved with the figure. The current DefaultFigureVisible value is ignored by openfig()
Something is setting the figure Visible to off before the savefig() . DefaultFigureVisible could be involved in the case of code that uses figure() and does drawing and savefig() and you didn't happen to notice that it is not rendering on screen as it goes.
I never had to explicitly set to Visible, opening by command or not. In this case I was dragging the figure from the current folder to the command window, it autocodes a "uiopen(...)" and runs, I guess that counts as programmatical. "set(0,'DefaultFigureVisible','on')" did not work.
"You may have some startup code or script that is preemptively setting the DefaultFigureVisible to 'off'."
I just noticed the figures doing this were saved from a live script, figures created in normal script or directly in the command window are not doing this, they open as visible always. There's nothing setting the default to off, but maybe livescript figures just work differently in the background...? guesswork...
What I have experienced difference in the Live Script figures:
  • They save additional metadata like the figure layout/positioning along with the normal figure data.
  • The default value for the 'Visible' property is 'off' when opening Live Script figures programmatically.
  • The figure 'WindowState' property defaults to 'docked' instead of 'normal'.
So when opening a figure saved from a Live Script, MATLAB applies these default settings which causes the figure to open invisibly docked. Setting 'DefaultFigureVisible' to 'on' doesn't override the Live Script defaults. You'd need to explicitly set 'Visible' and 'WindowState' when opening:
h = openfig('liveScriptFigure.fig');
set(h, 'Visible', 'on','WindowState','normal')
ok, I'll try to force a Visible='true' before saving next time I run this script... but again, it was never necessary before, it is really weird...
Ah, LiveScript. It handles figures a bit differently, as by default the figures it generates are to be displayed either inline or to the right margin, instead of in a different window.
I think this ought to be a bug. I'm experiencing this issue as well when saving from a livescript. I understand that fig properties in a live script have visibility set to off. But I don't want my figs to have to open in a window just to save them; it's time consuming and takes extra resources. It would be nice if saveas itself was edited by Mathworks so that it always sets figure visibility to 'on' for the saved fig. This is just an artifict of live scripts not playing nicely with saved figures. Nobody wants to open an invisible figure. It just doesn't make sense.
I want to open invisible figures. I want to be able to configure the settings of the figure and then open it; that is a lot more efficient than opening it visible and then configuring the settings.
I'm only saving .figs so I can point someone else to that directory and they can open and place markers and see it. I don't save figs for later MATLAB use. It doesn't help when they open it and they're invisible. It's a bug - that should not be the default implementation. If you want to programmatically override default behavior, that's fine. But the 90% use case should be default.

Sign in to comment.

Tags

Asked:

on 18 Aug 2023

Commented:

on 13 Feb 2024

Community Treasure Hunt

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

Start Hunting!