Transparent background for figures

Asked by Daniel on 31 Oct 2011
Latest activity Commented on by Daniel on 9 Dec 2011

I get the following warning in r2011a

set(gcf, 'Color', 'None')
Warning: Setting the ColorSpec to 'none' for a figure will not be allowed in a future release.

I use the "none" color so that I can print pdf and eps files with transparent backgrounds. How are you supposed to set a transparent background?

1 Comment

Fangjun Jiang on 31 Oct 2011

+1. I'd like to know about 'transparent'.

Daniel

Products

No products are associated with this question.

3 Answers

Answer by Oliver Woodford on 14 Nov 2011
Accepted answer

You can edit the eps file generated by print, and remove the line which creates the background rectangle, thus making the background transparent.

Or you can use the latest version of export_fig, which will do this for you when the -transparent option is specified, and will allow you to export to pdf as well.

2 Comments

Daniel on 14 Nov 2011

Will take a look at how you edit the eps file in export_fig (and will likely accept your answer once I do). I still don't understand why the change in MATLAB was made.

Daniel on 9 Dec 2011

I finally got a chance to dig around in export_fig. For those silly enough not to use export_fig, the line in the eps file can be found with: regexp(l, ' *0 +0 +\d+ +\d+ +rf *[\n\r]+', 'start').

Oliver Woodford
Answer by Jan Simon on 31 Oct 2011

Digging in the source of print I've found the colornone command in 2011b. It has a help section, but is not included in the local or net docs.

But the warning appears also. The print command simply disables the warning:

warning('off','MATLAB:hg:ColorSpec_None')

This does not look very trustworthy.

2 Comments

Daniel on 31 Oct 2011

It seems odd that they are taking away functionality without providing a replacement. This usually means you are doing something odd. In this case, I don't think I am. My guess is that there will be a replacement by the time it is obsolete.

Oliver Woodford on 14 Nov 2011

Note that this is not just a warning. The behaviour of print in R2011b has changed over R2011a. You cannot now save an eps or pdf with no background color, and TMW has provided no way around this (to my knowledge).

Jan Simon
Answer by Fangjun Jiang on 31 Oct 2011

What do you mean transparent? Do you mean white background color? Would the pdf or eps file come out the same as set(gcf,'Color','None') as set(gcf,'Color',[1 1 1])?

I used to use whitebg(). But it's not really white background anymore since the default color is [.8 .8 .8]. whitebg() just turns it to [.3 .3 .3]. Same is the function colordef(). I

8 Comments

Fangjun Jiang on 31 Oct 2011

PowerPoint is the same. Anyway, I certainly can understand the difference between transparent and white. Thanks!

Daniel on 1 Nov 2011

I just looked at your comments again more closely. You need:

set(gca,'color','none')

Fangjun Jiang on 1 Nov 2011

It's still the same for me, in MS Word or PowerPoint. In your question, shout it be gca or gcf?

Fangjun Jiang

Contact us