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

When doing a RegionPlotand then exporting (or saving from the front end) as PDF or EPS, there are small white lines in the filling of the region. Here's an example created with RegionPlot[x^2+y^2<1,{x,-1,1},{y,-1,1},PlotStyle->Black]:
output of RegionPlot after saving as EPS

Is there any way to prevent those white lines while keeping it vector graphics? Note that those lines do not appear on screen, only in the exported file.

Also note that my actual graphics is more complex and especially has several different-coloured regions.

share|improve this question
up vote 24 down vote accepted

The suggestion to use Antialiasing->False doesn't really solve the problem. I don't have a single solution that's appropriate in all cases, but I think one of the approaches I list on the following web page will work: Avoiding artifacts in shaded contour and density plots


The following method from the linked article solves the problem:

Instead of exporting the image (assumed to be stored in im1), export the modified graphics

im1 /. {EdgeForm[], r_?(MemberQ[{RGBColor, Hue, CMYKColor, GrayLevel}, Head[#]] &), i___} :> {EdgeForm[r], r, i}

This replaces the invisible edges of the polygons (EdgeForm[]) in your graphic (called im1 here) by edges of default thickness and with a color matching at least one of the neighboring polygons. The new edges then help fill any empty space between the shaded areas.

Edit 2

My solution relies on finding colored polygons without colored edges by looking for EdgeForm[] followed by a color in the graphic im1.

Based on the answer by Mr. Wizard and kguler here, one can also make the above work better with custom colors and future additions to the built-in color choices:

colorQ = FreeQ[Quiet@Darker@#, Darker] &;
im1 /. {EdgeForm[], r_?colorQ, i___} :> {EdgeForm[r], r, i}
share|improve this answer
Thanks. The replacement rule given in that file works great, and now I even get PDFs which render correctly in acroread. Therefore I've switched the accepted answer to yours. To avoid depending on external links, I'll add that rule to your answer. – celtschk Mar 6 '12 at 16:38
Thanks for adding the rule definition - I'll just add a little explanation then. – Jens Mar 6 '12 at 16:55
I had the same problem and the replacement rule solved it except when I assembled and converted the files to PDF 1.4 (with Adobe Illustrator) for inclusion in a TeX document the problem reappeared. – s0rce Mar 6 '12 at 18:28
With Adobe Illustrator CS3, I have no problem exporting to PDF 1.4. Not knowing your specific issue, I can only suggest to replace EdgeForm[r] by EdgeForm[{r,Thickness[Small]}] above. – Jens Mar 6 '12 at 18:59
Jens, since you've obviously put some thought into this I'd like to ask: is there is a reason the fills are triangulated like that to begin with, rather than complete vector shapes? (+1, btw) – Mr.Wizard Mar 6 '12 at 23:16

Surely this is a manifestation of the problem described in:

Antialiasing option behaves weird (polygon edges visible in ContourPlot)

Therefore, you should try using Style[plot, Antialiasing -> False] or other methods to disable anti-aliasing.

The cause is as I thought but my suggestion Antialiasing -> False was naive as that would only affect the antialiasing in the Mathematica Front End, and the problem is the result of antialiasing in the PDF or EPS viewer.

Jens already provided an excellent solution. However in an effort to make this answer useful a generic solution is to export a stack of copies of the graphic which should serve to fill in the partially transparent gaps in the rendering. Using Sumatra PDF reader only a second copy is needed.

plot = RegionPlot[x^2 + y^2 < 1, {x, -1, 1}, {y, -1, 1}, PlotStyle -> Black];

Export["plot.pdf", Show[plot, plot]]


Of course of the plot contains meaningful transparency this will damage it, but in most cases it is a quick shorthand that is easy to remember and works pretty well.

Somehow I had missed a closely related question which Jens directed me to. I believe it is a solution to this problem:

How can all those tiny polygons generated by RegionPlot be joined into a single FilledCurve?

share|improve this answer
Thanks, it indeed was an antialiasing problem. Except that at least for the EPS, it was not Mathematica, but gv doing the antialiasing (so the eps file is actually fine; only the display was wrong; switching off antialiasing in gv fixed the problem). – celtschk Mar 6 '12 at 14:37
The fact that he still needs to mess with the display in gv means that the export without antialiasing cannot have solved the problem. – Jens Mar 6 '12 at 16:10
I agree that the FilledCurve approach also solves this problem for RegionPlot. But it's worth keeping in mind that the underlying issue also affects ContourPlot, DensityPlot and related functions. I don't think the FilledLine trick can easily be generalized to these types of plots because their colors aren't "binary" and they can't even be guaranteed to have lines that enclose the shaded areas. – Jens Mar 9 '12 at 4:03

One should note, that in Mathematica Version 9 this issue no longer appears. I tried it here on Linux x86 (64-bit):

RegionPlot[x^2 + y^2 < 1, {x, -1, 1}, {y, -1, 1}, 
  PlotStyle -> Black];
Export["tmp/region.pdf", %]

enter image description here

Maybe someone can confirm this for other systems.

share|improve this answer
I really need to get MMA 9. – s0rce Dec 1 '12 at 0:25
MMA 9 on mac also works without problems. – xslittlegrass May 12 '13 at 21:34
The problem shows up when you have multiple functions, or you use opacity! – Lina Apr 21 '14 at 18:20
@Lina The question was not about Opacity, but I agree that there are still a lot of issues about vector graphics in Mathematica. You may want to read here and here. – halirutan Apr 21 '14 at 19:16
I still observe this issue on MMA 10 over linux, depending on the pdf reader. (In particular, evince is generally OK but the TexMaker inbuilt one is not.) – Emilio Pisanty May 22 '15 at 13:29

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.