Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to output a simple plot with a legend and the output keeps coming out with a gray background. A simple example is the following:

Plot[{Sin[x], Cos[x]}, {x, 0, 2*3.14}, PlotStyle -> {Red, Blue}, 
PlotLegends -> SwatchLegend[{Red, Blue}, {"sin(x)", "cos(x)"}]]
Export["trig.pdf", %]

which outputs (notice the gray background!),

$\hspace{1cm}$enter image description here

I have tried setting "Background->White" in different places, but only managed to have certain regions to get a white background. How can I get an export the image with a white background (and keeping it in pdf format)?

I am using Mathematica V9 on Linux.

Edit:

  1. I just upgraded to V10 with hopes that it would fix the issue and the problem still persists.
  2. pdf and eps both show the gray background while image formats such as jpg don't. Oddly enough svg also doesn't show the gray background.
  3. I'm using Ubuntu 14.04 with Intel 4th generation graphics card.
  4. I tried using different pdf viewers and they all showed the same gray background.
share|improve this question
    
Doesn't happen with M9.0.1 on OSX –  halirutan Apr 4 at 13:46
1  
I cannot reproduce this with M9.0.1 on Linux. Are you using a non-default style sheet in your notebook? –  Szabolcs Apr 4 at 14:02
    
I sometimes have problems with pdf exports. Not the same. Have you tried exporting it to another format and get the same problem? –  Mockup Dungeon Apr 4 at 14:39
2  
FWIW, I have the same problem with MMA 9.0.0 on Win7 64bit. Shows grey in both SumatraPDF and Adobe Reader. I assumed it might be fixed with 9.0.1... –  tkott Apr 4 at 16:57
1  
@JeffDror If you are around, would you mind joining Mathematica Chat to discuss this problem? –  halirutan Jul 15 at 2:16

1 Answer 1

up vote 8 down vote accepted
+50

After a rather long debugging session in our chat we could determine the reason of the problem and come up with a workaround.

In short, we first tried whether the issue appears for the most basic Graphics[], which it didn't. As it turned out the gray background is introduced by using PlotLegends as in the example above. We went further by comparing AbsoluteOptions of the created graphics and the Options[SwatchLegend] settings. Everything looked the same on the OP's and my machine.

I then kind of remembered (guessed, whatever) that graphics export is done with the printing style sheet and we tried to set Format => Screen Environment to Printout. This was the first success, because this turned the graphics indeed gray.

Now, we knew the reason, but we couldn't find the exact source. Making a complete diff between our Core.nb stylesheet files showed nothing at all. I guess that this setting can be found somewhere else, although the OP stated that this issue persists for over 2 years and has survived even complete operating system changes.

The workaround is as simple as it is intuitive. Open the Preferences and then the Options Inspector and set the PrintingStyleEnvironment to Printout Gray (Is this awesome? It is, isn't it?)

inspector

If this issue would appear on my machine, I would probably take a closer look at my

FileNameJoin[{$InstallationDirectory,"SystemFiles","FrontEnd","StyleSheets"}]

directory and grep through the Default.nb and the other things to find where this is set. I hope the workaround and the information help someone to track this down.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.