Avoiding white lines inside filled area in RegionPlot exported as PDF or PS

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

Edit:

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}

Edit 3

Thanks to @becko for pointing out that there is a new command ColorQ in version 10 that can do the same as above. So you can replace colorQ in the previous edit with ColorQ.


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]]

SystemOpen["plot.pdf"]

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?


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.