Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Why f=figure('visible','off') doens't work?!!!!!

Subject: Why f=figure('visible','off') doens't work?!!!!!

From: Camille Couzi

Date: 30 Nov, 2011 03:50:10

Message: 1 of 7

Hi matlabers,
stangre behaviour that I can't understand:
I am developping a code that creates figures and save them, but as it is in a loop over thousands of steps, I don't want to see the figures, just save them.
I knpw this is a very common question and I have made some research before posting this message, but I can't understand why, when I write in my loop
f=figure('visible','off')
and then I define my plot, and I use saveas or print,

the figure appears on my screen!!!!
How can I solve this problem?!
Thanks in advance for your help,
Camille.

Subject: Why f=figure('visible','off') doens't work?!!!!!

From: ade77

Date: 1 Dec, 2011 17:09:07

Message: 2 of 7

"Camille Couzi" <cco@dhi.com.sg> wrote in message <jb495i$sh6$1@newscl01ah.mathworks.com>...
> Hi matlabers,
> stangre behaviour that I can't understand:
> I am developping a code that creates figures and save them, but as it is in a loop over thousands of steps, I don't want to see the figures, just save them.
> I knpw this is a very common question and I have made some research before posting this message, but I can't understand why, when I write in my loop
> f=figure('visible','off')
> and then I define my plot, and I use saveas or print,
>
> the figure appears on my screen!!!!
> How can I solve this problem?!
> Thanks in advance for your help,
> Camille.

customize below for ur specific need:

for kk = 1:5
f = figure('Visible', 'off');
plot_axes = axes('Parent', f);
plot(plot_axes, [1 2 3 4], rand(1,4))
close(f);
end

Subject: Why f=figure('visible','off') doens't work?!!!!!

From: matt dash

Date: 1 Dec, 2011 18:57:08

Message: 3 of 7

"Camille Couzi" <cco@dhi.com.sg> wrote in message <jb495i$sh6$1@newscl01ah.mathworks.com>...
> Hi matlabers,
> stangre behaviour that I can't understand:
> I am developping a code that creates figures and save them, but as it is in a loop over thousands of steps, I don't want to see the figures, just save them.
> I knpw this is a very common question and I have made some research before posting this message, but I can't understand why, when I write in my loop
> f=figure('visible','off')
> and then I define my plot, and I use saveas or print,
>
> the figure appears on my screen!!!!
> How can I solve this problem?!
> Thanks in advance for your help,
> Camille.

Many of the saveas/print file formats require the figure to be visible on screen in order to export it, hence its visibility is turned on. I know tiff does not require this... maybe some others too.

Subject: Why f=figure('visible','off') doens't work?!!!!!

From: ade77

Date: 1 Dec, 2011 19:11:08

Message: 4 of 7

> Many of the saveas/print file formats require the figure to be visible on screen in order to export it, hence its visibility is turned on. I know tiff does not require this... maybe some others too.

With due respect, that is not entirely correct.

f = figure('visible', 'off');
 plot([1 2 3 4], [4 5 6 7];
 saveas(f, 'myfile.png')

this will save the file.

My suspision is that the OP is creating multiple figures with the for loop , and only makes the first figure(handle) invisible, and consequently the other figure handles are visible.

Subject: Why f=figure('visible','off') doens't work?!!!!!

From: ade77

Date: 1 Dec, 2011 19:18:08

Message: 5 of 7

The code below will save the 5 files, without any of the figure been visible:

for kk = 1:5
f = figure('Visible', 'off');
plot_axes = axes('Parent', f);
plot(plot_axes, [1 2 3 4], rand(1,4))
saveas(f, ['myfile' num2str(kk) '.png']); %save figure here
close(f);
end

Subject: Why f=figure('visible','off') doens't work?!!!!!

From: matt dash

Date: 1 Dec, 2011 22:18:08

Message: 6 of 7

"ade77 " <ade100a@gmail.com> wrote in message <jb8jgc$gah$1@newscl01ah.mathworks.com>...
> > Many of the saveas/print file formats require the figure to be visible on screen in order to export it, hence its visibility is turned on. I know tiff does not require this... maybe some others too.
>
> With due respect, that is not entirely correct.

You might be right... last i checked bmp required it to be visible to print. Now when i try to use saveas bmp with an invisible figure it gives an out of memory error, though it does turn the visibility on before that happens. (Unfortunately it looks like this happens in the hardcopy.p function) All other formats seem to save just fine. I wouldnt be surprised if this had something to do with the operating system too...

I think the OP will need to post some code....

Subject: Why f=figure('visible','off') doens't work?!!!!!

From: ade77

Date: 1 Dec, 2011 22:33:08

Message: 7 of 7

"matt dash" wrote in message <jb8uev$pb8$1@newscl01ah.mathworks.com>...
> "ade77 " <ade100a@gmail.com> wrote in message <jb8jgc$gah$1@newscl01ah.mathworks.com>...
> > > Many of the saveas/print file formats require the figure to be visible on screen in order to export it, hence its visibility is turned on. I know tiff does not require this... maybe some others too.
> >
> > With due respect, that is not entirely correct.
>
> You might be right... last i checked bmp required it to be visible to print. Now when i try to use saveas bmp with an invisible figure it gives an out of memory error, though it does turn the visibility on before that happens. (Unfortunately it looks like this happens in the hardcopy.p function) All other formats seem to save just fine. I wouldnt be surprised if this had something to do with the operating system too...
>
> I think the OP will need to post some code....

You are right, there might be issue with some formats.
I am of the impression that the OP wants the figure invisible, so that it can reduce memory usage, however, a nice approach will just be to use one figure at a time and delete that figure once it is saved, so that only one figure is active at a time(visible or not).
I think u are also right about the operating system been an issue too. What I do not know however is , how the video card plays a role in this.... I mean if the figure is visible, whether memory is still used internally for display or not.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us