Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to export a graph as a graphic to an SVG file with transparent background. When the background is specified as a color (or unspecified), it works just fine. When the background is specified as None, it offsets the graphic down and to the right a bit and ends of cutting off part of the graphic.

g = CompleteGraph[7];
g = GraphicsGrid[{{g}}];
Export["good.svg", g, Background -> Pink];
Export["bad.svg", g, Background -> None];

Transparency works perfectly as expected when the graphic is exported to PNG. Is this a bug, or am I just missing something here?

I'm running Mathematica on Linux 64-bit.

Here's a screenshot of what I am seeing when I open the bad.svg in the gnome image viewer (with some style changes made to the graph for visibility). Note that the image is cut off on the bottom and on the right. When I open bad.svg in chromium or in firefox, it appears fine.


share|improve this question
Can you please detail your OS and Mathematica version? – Yves Klett Jun 30 '14 at 5:18
up vote 6 down vote accepted

Although I do see a difference between the contents of bad.svg when I export with version 8.0.4 and 9.0.1, the svg is displayed in exactly the same way by Google Chrome. The display does indeed show a white background in Safari, though, when exported from Mathematica 8.0.4 on OS X. So we could now argue whether this is the fault of the browser, or the fault of Mathematica. I think it is indeed a problem with Mathematica's Export in version 8.0.4.

What happens is that there is an unnecessary line in the exported SVG file, located at a nominally inaccessible position:

<rect fill='rgb(100%,100%,100%)' stroke='none' x='-2.2518e+15' y='-2.2518e+15' width='4.5036e+15' height='4.5036e+15' />

This is apparently recognized by Google Chrome as something that can't be displayed. But in Safari, it is in fact displayed as a white background. I checked this by embedding the file in an HTML document with

<body style="background:gray;"><img src="bad.svg">

When I remove the offending rect from the SVG file, the display in Safari is fixed:

bad good

Since I can't be sure that this faulty line is always generated the same way when exporting SVG with no background, I can at this point only recommend removing this line from the SVG file manually. It's line 6 in the exported file.

In version 9.0.1, I don't see this line in the exported file, and there is no white background in any browser that I have tried.

Edit to address sizing

As mentioned in the comment, there is a problem in that the size of the exported SVG isn't always correctly identified. To fix this, you can use the function svgExport from my answer to "Embed Code Into Image". It makes the necessary replacements in the exported code.

share|improve this answer
For me, the transparency works fine in both google-chrome and firefox when I embed it into an HTML file, but the image is cut off again in firefox (much more so than in the gnome image viewer screenshot above). Also, using Mathematica, my Bad.SVG file doesn't have a line like you describe. There is not line starting with <rect fill= but instead on line 6 I've got <polyline fill=. Link the the SVG here. – mapierce271 Jun 30 '14 at 6:08
I agree about Firefox, but it can be easily fixed with <img src="bad.svg" style="width:360px;height:360px;". It's unrelated to the background issue, see here. So basically, one should call this a bug that has apparently been fixed in version 9.0.1 but not in 9.0.0. – Jens Jun 30 '14 at 16:42
For the Firefox problem, I added a link to my answer that fixes this issue. – Jens Jun 30 '14 at 17:03

Your Answer


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.