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.


  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.
  • $\begingroup$ Doesn't happen with M9.0.1 on OSX $\endgroup$
    – halirutan
    Commented Apr 4, 2014 at 13:46
  • 1
    $\begingroup$ I cannot reproduce this with M9.0.1 on Linux. Are you using a non-default style sheet in your notebook? $\endgroup$
    – Szabolcs
    Commented Apr 4, 2014 at 14:02
  • $\begingroup$ I sometimes have problems with pdf exports. Not the same. Have you tried exporting it to another format and get the same problem? $\endgroup$ Commented Apr 4, 2014 at 14:39
  • 2
    $\begingroup$ 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... $\endgroup$
    – tkott
    Commented Apr 4, 2014 at 16:57
  • 1
    $\begingroup$ @JeffDror If you are around, would you mind joining Mathematica Chat to discuss this problem? $\endgroup$
    – halirutan
    Commented Jul 15, 2014 at 2:16

2 Answers 2


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?)


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


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.

  • $\begingroup$ I have exactly the same problem, and also only with PlotLegends.. However I don't get your workaround to work, the only three options for PrintingStyleEnvironment are "SlideShow", "Working", and "Printout". None of these three solve the problem, neither does manually typing "Printout Gray". Did I need to install another stylesheet first to get that to work? $\endgroup$ Commented Dec 4, 2017 at 10:58
  • $\begingroup$ @freddieknets It is really hard to say what is happening on your machine. You don't need to install a style-sheet. The problem should be in your existing one. What exact operating system and Mathematica version are you using? $\endgroup$
    – halirutan
    Commented Dec 4, 2017 at 12:56
  • $\begingroup$ I am using Mathematica on macOS 10.12.6 $\endgroup$ Commented Dec 4, 2017 at 14:15
  • $\begingroup$ Unfortunately, I have only on my OSX here. Otherwise, if we had the exact same versions, you could send my your stylesheet directory packed as zip and I would try to make a complete diff of the files. Do you have the possibility to update to 11.2 or 11.1.1? $\endgroup$
    – halirutan
    Commented Dec 4, 2017 at 14:29
  • $\begingroup$ Unfortunately I don't have premier service, so no (unless I am misunderstanding conditions to upgrade). $\endgroup$ Commented Dec 5, 2017 at 19:27

I recently encountered this problem, and none of the above solutions solved my problems (on version However, I have found a solution which worked for me and should be independant of version.

On my version, the problem specifically occurred when using the Report stylesheet, but vanished with the Default one. The trick was to make a custom stylesheet that includes all of the style definitions from Report except the offending Graphics cell definition.

To achieve this practically, I switched to the Default stylesheet on the target notebook, opened a new mathematica notebook with a Report stylesheet , went to Format > Edit stylesheet on both and clicked Report/StandardReport.nb on the latter to load the Report's default cell definitions. Then I copied all the Report's cell definitions over to the Private Style Definitions for XXX.nb notebook and then went in and removed the offending local definition for graphics in Styles for Input and Output Cells as well as changing the background color for Output to white (select the cell then Format > Background Color > White).

Graphics now have a white background for both the image and text labels (an issue raised in another StackMMA question).

This new stylesheet can then be saved Default by following these instructions.

  • $\begingroup$ I think this is the problem in my case as well. I was using StandardReport and any plot with legends came out with a gray background. I switched to Default and everything was fine. I'll try your fix, thanks. $\endgroup$
    – amzon-ex
    Commented Sep 26, 2022 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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