keep figures from popping up when running.
Show older comments
I am doing a lot of batch processing in which I creating many figures. I would like to keep these figures in the background while running the Matlab code without the Figure window popping up each time a new figure is created. Is there an easy way to do this? When the figure pops up it disrupts anything else you are doing on the computer.
4 Comments
Michael Marcus
on 15 Jun 2011
Michael Marcus
on 15 Jun 2011
Walter Roberson
on 15 Jun 2011
Edited: Walter Roberson
on 20 Aug 2019
I suggest you try export_fig
which can save a figure.
I have not experimented with it or looked at how it works, so I do not know if it would trigger a pop-up.
Jan
on 15 Jun 2011
@Michael: AFAICS the problem concerns Linux only. Therefore I asked which OS you are using.
Does PRINT move the figure to the front also?
Answers (9)
Walter Roberson
on 15 Jun 2011
1 vote
Someone indicated, though, that they could not get the figures to be saved when they used this technique. Possibly Oliver's export_fig would work. Or running MATLAB without a display and using one of the print() options that are documented as not needing a display.
4 Comments
Walter Roberson
on 15 Jun 2011
Partial work-around: instead of using figure() for each new figure, re-use the existing figure. You can clf() it if you want to wipe its contents relatively clean.
Walter Roberson
on 15 Jun 2011
I'm not certain if I understand what you are asking.
I am using Ubuntu 10.04 . In this version, at least with the default gnome window policies, new figure() _do_ show up in the foreground. If you have switched virtual desktops, new figures show up on the desktop you are currently on rather than on top of the desktop that MATLAB was running on (this is a nuisance sometimes.)
I have tested, and getframe() does cause a figure to become visible in this configuration.
Walter Roberson
on 15 Jun 2011
getframe() also pops the relevant figure to the front in this version.
Jan
on 15 Jun 2011
@Walter: Thanks, now I'm starting to understand the problem. Under Windows new figures are created on top of all other Matlab figures, but below the program which has the focus. And GETFRAME replies the contents of the screen at the figure (or axes) coordinates - if the figure is not topmost this is most likely not the wanted picture.
Gurudatha Pai
on 15 Jun 2011
I won't promise you that this is the best solution, however, is one of them.
You could set the 'visible' property off the figure object to 'off'. It can be done something like this,
h1 = figure();
set(h1, 'Visible', 'off');
plot(x,y)
and when you want it to be shown,
set(h1, 'Visible', 'off');
or
figure(h1)
should also work.
4 Comments
Michael Marcus
on 15 Jun 2011
Walter Roberson
on 15 Jun 2011
If you do this at the command line, then the command interpreter will have an automatic drawnow() before it gives the command prompt. You need to combine the figure() command and the set() command on the same line if you want to test from the command line.
Michael Marcus
on 15 Jun 2011
Watson Ly
on 20 Aug 2019
figure_handle = figure(1)
figure_handle.WindowState = 'minimized'
.....
set(0, 'CurrentFigure', figure_handle)
plot([1:10],[1:10])
it worked for me
Jan
on 15 Jun 2011
As long as I do not use Java or Windows-API methods to set the topmost flag of the window, I do not get this behaviour.
pause(10);
figure;
% Enable the Explorer, NotePad, any other program
% After the 10 secs have passed, ...
% the figure is created - in the background!
Which OS are you using? Do you create figures with WindowStyle='modal'?
3 Comments
Michael Marcus
on 15 Jun 2011
Jan
on 15 Jun 2011
@Michael: I did not even try to show a solution. I still do not see the problem at all, because the figures are *not* created in the forground at all - are they? I simply cannot confirm this: "When the figure pops up it disrupts anything else you are doing on the computer".
Of course GETFRAME does not work with figures not shown in the foreground, but you do not mention any problems with bad output here, but that the figure pops to the foreground. But PRINT handles background, out of visible screen area and Visible=off figures also.
Can somebody enlighten me, please?
Michael Marcus
on 16 Jun 2011
Fangjun Jiang
on 15 Jun 2011
I think you can do this. It will pop up only once. The point is to re-use the figure. You can delete all its contents once they are printed. You can step through it to see the effect.
h=figure;
set(h,'visible','off');
plot(1:10);
print(h);%use your own command, this sends it to the printer
delete(get(h,'children'));
subplot(2,1,1); %do this just for illustration
plot(1:10);
subplot(2,1,2);
plot(1:10);
set(h,'visible','on');
delete(get(h,'children'));
2 Comments
Fangjun Jiang
on 15 Jun 2011
Or even better, use clf(h) instead of delete(). Thanks to Walter's comment.
Walter Roberson
on 15 Jun 2011
The delete() code shown here would not get hidden handles. Some figure children are created with hidden handles.
Michael Marcus
on 16 Jun 2011
1 vote
2 Comments
Nik Rocky
on 25 Jun 2020
Hello Michael, can you upload here your solution? Your link is not working and I have the same Problem (Kubuntu 16.4). Thank you
Oliver Woodford
on 16 Jun 2011
1 vote
Fred Sigworth
on 5 Jan 2018
0 votes
I have this sort of problem too. I use Matlab on Mac OS. Suppose I have a program that draws in two figure windows which are overlapping. When I execute
figure(1); plot(some_data_vector); figure(2); plot(another_data_vector);
this puts figure 1 in front, draws on it, then puts figure 2 in front and draws on it. Is there any way I can update figure 2 without it becoming the front window?
I also run Matlab on a linux machine, and use XQuartz as the X-terminal. In that situation calling figure(1) puts that figure window in front of everything on the screen, which is more annoying still. Again, is there a way to draw in a figure (and have the graphics on the screen update) without the figure window being in front?
6 Comments
Walter Roberson
on 5 Jan 2018
"Is there any way I can update figure 2 without it becoming the front window?"
Yes: do not figure() it.
fig1 = figure(1);
ax1 = axes('Parent', fig1);
fig2 = figure(2);
ax2 = axes('Parent', fig2);
Now enter your loop, and
plot(ax1, some_data_vector);
plot(ax2, another_data_vector);
"In that situation calling figure(1) puts that figure window in front of everything on the screen"
That would be a function of the window manager, and there are probably relevant X options. It has been quite a number of years since I last programmed in X so the names of the appropriate control structures are not coming to mind at the moment.
Stephan Moeller
on 29 Jun 2020
how would we do it instead of plot : mesh ?
Walter Roberson
on 29 Jun 2020
You would use the same way: you can pass an axes as the first parameter to mesh().
Many plotting functions accept an axes as a first parameter, but not all of them do. The ones that accept plotting into an axes but do not accept passing in an axes as the first parameter, you would pass the 'Parent' option to.
There are some plotting routines that do not accept passing an axes and do not accept 'Parent' either: if you encounter one of those routines, you usually cannot stop the routine from bringing the figure to the front... sometimes you cannot even stop the routine from creating a new figure entirely. bode() for example always creates a new figure.
Stephan Moeller
on 3 Jul 2020
Edited: Stephan Moeller
on 3 Jul 2020
Unfortunatly Figure 1 still pops up every time its plotted :
count=10;
Matrix1 = magic(100);
for i=1:count
fig1 = figure(1); ax1 = axes('Parent', fig1);
mesh(ax1,Matrix1);
pause(1)
end
Walter Roberson
on 3 Jul 2020
I specifically said above, "Yes: do not figure() it."
No calls to figure() inside your loop.
fig1 = figure(1);
ax1 = axes('Parent', fig1);
count=10;
Matrix1 = magic(100);
for i=1:count
mesh(ax1, Matrix1);
pause(1);
end
Stephan Moeller
on 5 Jul 2020
ok. Sorry, missed that.
How would it work with a subplot ?
( fig1 = subplot(2,1,1);figure(1); )
Stephan Moeller
on 9 Jul 2020
Got it :
count=5;
Matrix1 = magic(100);
Vector1=rand(10,1);
figure(4);
ax1= subplot(2,1,1);
ax2= subplot(2,1,2);
AX=[ax1,ax2];
for i=1:count
mesh(AX(1), Matrix1);
plot(AX(2), Vector1);
pause(0.5);
end
Victor v. Spaandonk
on 5 Aug 2021
0 votes
I feel like this didn't use to be the default behavior for me but now it is (figures popping up over other windows applications).
could it be a setting?
I'm at R2018b
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!