# Problem with exporting RegionPlot as PDF

I have the following RegionPlot (which code I don't present since it comes from a long expression): When I right click on it (within the notebook) and try to save it as PDF, for some reason I get the following image as the exported PDF With the mesh-like effect on it. PNG works fine, but I would prefer to have it as a PDF. Any idea why this is happening and how to fix it? Other region plots I've done didn't yield this effect.

• Can't reproduce it in 12.3.1 on Windows 10. See here the result obtained by me. Oct 17 at 13:52
• I can reproduce it with the RegionPlot[x^2 + y^3 < 2, {x, -2, 2}, {y, -2, 2}]. Oct 17 at 15:19
• See also Avoiding white lines inside filled area in RegionPlot exported as PDF or PS for a related problem whose solution may apply here as well. Oct 17 at 15:30

As a workaround we can express the Polygon complex through its boundary representation:

plot = RegionPlot[x^2 + y^3 < 2, {x, -2, 2}, {y, -2, 2}];

Export["/Users/ghurst/Desktop/plot.pdf", plot];

gcps = Position[plot, gc_GraphicsComplex, ∞];

breps = BoundaryDiscretizeGraphics /@ Extract[plot, gcps];

faceform = Append[ColorData[97, 1], 0.3];
edgeform = Directive[AbsoluteThickness[1.6], ColorData[97, 1]];

newgcs =
Show[BoundaryMeshRegion[#,
MeshCellStyle -> {2 -> {FaceForm[faceform],
EdgeForm[edgeform]}}]] & /@ breps;

plot2 = ReplacePart[plot, Thread[gcps -> newgcs[[All, 1]]]];

Export["/Users/ghurst/Desktop/plot2.pdf", plot2];


Comparison: This problem is one of those things that comes up a lot, but each question has slight differences that make agreement about being a duplicate is hard to reach. Here is a solution that can achieved by a slight tweak to one line in @Szabolcs' answer:

cleanRegionPlot@RegionPlot[..]


For instance:

Export[FileNameJoin[{\$TemporaryDirectory, "clean.pdf"}],
cleanRegionPlot@RegionPlot[x^2 + y^3 < 2, {x, -2, 2}, {y, -2, 2}]];
First@Import[%] From @Szabolcs' code:

cleanRegionPlot[cp_Graphics] :=
Module[{points, groups, regions, lines},
groups =
Cases[cp, {style__, g_GraphicsGroup} :> {{style}, g}, Infinity];
points =
First@Cases[cp, GraphicsComplex[pts_, ___] :> pts, Infinity];
regions = Table[
Module[{group, style, polys, edges, cover, graph},
{style, group} = g;
polys =
Join @@ Cases[group, Polygon[pt_, ___] :> pt, Infinity];
edges = Join @@ (Partition[#, 2, 1, 1] & /@ polys);
cover = Cases[Tally[Sort /@ edges], {e_, 1} :> e];
graph = Graph[UndirectedEdge @@@ cover];
{Sequence @@ style,
FilledCurve[
List /@  Line /@ First /@
Map[First,
FindEulerianCycle /@ (Subgraph[graph, #] &) /@
ConnectedComponents[graph], {3}]]}], {g, groups}];
lines = Cases[cp, {__, _Line}, Infinity]; (* only change *)
Graphics[GraphicsComplex[points, {regions, lines}],
Sequence @@ Options[cp]]
];


Possible duplicates:

Many related:

specifying the PlotStyle solve it too

RegionPlot[x^2 + y^3 < 2, {x, -2, 2}, {y, -2, 2}, PlotStyle -> Yellow] • (+1) That's funny that there is such a simple workaround that everyone overlooked. What actually gives the desired effect here is setting PlotStyle -> Opacity or PlotStyle -> Opacity. Another way is to make a replacement: /. Opacity[_] -> Opacity. PlotStyle -> Yellow just removes the default Opacity[0.3] styling directive. Nov 10 at 1:02

Since the problem appears due to the default Opacity[0.3] color directive, we can avoid it by converting color directives with transparency into the corresponding color directives without transparency. By inspecting the internal structure of the default plot we can find that the default style is:

Directive[RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[0.3]]


The corresponding color without transparency (assuming white background) is:

opacity = 0.3;
color = RGBColor[0.368417, 0.506779, 0.709798];
equivalentColor = RGBColor[opacity*List @@ color + (1 - opacity)]

RGBColor[{0.8105251, 0.8520337, 0.9129394}]


Hence the default style will be reproduced with:

pl = RegionPlot[x^2 + y^3 < 2, {x, -2, 2}, {y, -2, 2},
PlotStyle -> RGBColor[{0.8105251, 0.8520337, 0.9129394}]] Here is how it looks exported to PDF:

Export["pl.pdf", pl] // SystemOpen 