7
$\begingroup$

I have the following polygon:

enter image description here

generated using this code (extracted from my previous question):

data = Table[{x, (x - 5)^2 + 3}, {x, 0, 10}];
p1 = ListLinePlot[data, Filling -> {1 -> {15, {Blue, None}}}];
p1 = Normal@p1 /. 
   Polygon[x_] :> 
    Polygon[x, 
     VertexColors -> (Blend[{RGBColor[0, 0, 1, .5], 
           RGBColor[0, 0, 1, 0]}, #] & /@ Rescale[x[[All, 2]]])];
polygon = First[Cases[Normal@p1, _Polygon, Infinity]];
Graphics[{EdgeForm[None], polygon}, AspectRatio -> 1]

The image above was generated via Export["test.png",%]. However, if I export to pdf instead, I see the boundaries of the polygons. This is a screenshot of the pdf:

enter image description here

How can I get rid of these blue lines?

This post seems related, but the solution there was to raster the polygon. That would make sense for thousands of polygons, but in this case it's only 7 of them so I suspect it should be possible to get a true vector format pdf out of this.

$\endgroup$
  • $\begingroup$ On my Mac I export as an eps and then open in Preview to convert to pdf. The lines do not show. $\endgroup$ – Bob Hanlon Jan 30 '17 at 18:09
  • $\begingroup$ I don't have a Mac, but on Linux the eps version has the lines as well. $\endgroup$ – Felix Jan 30 '17 at 18:15
  • $\begingroup$ I confirm the bug on Mathematica 11.0. I also tried the SetOptions[$FrontEnd, PrintingStyleEnvironment -> "Working"] method without success. $\endgroup$ – Johu Feb 1 '17 at 7:25
5
$\begingroup$

For me, AbsoluteThickness[-1] does the trick in

Graphics[{EdgeForm[{White, AbsoluteThickness[-1]}], polygon}, AspectRatio -> 1]

pdf screenshot

In the final PDF there are slight white lines visible. Those are artifacts of the displaying process (alpha blending) and won't be visible in the final print. Note that the white lines have constant thickness no matter how deep you zoom in.

Update

I downloaded the PDF you provided in the comments and on my OSX here it looks like this

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for the solution that works with transparency. I can't test the printing for lack of a printer. Is this alpha blending a general pdf issue or related to Mathematica? I have to say, though, that my lines are not white but still blue (only in constant thickness, as you say), showing like this both in Okular and in Acrobat Reader, see here for the pdf: filetea.me/n3w3CCJt2R5RTSPGKEg6gaVHg $\endgroup$ – Felix Feb 1 '17 at 15:51
  • $\begingroup$ @Felix I'm on OSX (now, I was on Linux earlier) and your PDF doesn't have the blue lines here. As I said, if the polygons do not overlap, what you experience is rendering artifacts of the PDF viewer. See my update in the answer. $\endgroup$ – halirutan Feb 1 '17 at 15:58
  • $\begingroup$ That's very strange. Also on OSX it shows blue lines for me when using Acrobat Reader. However, with Preview it's white lines. $\endgroup$ – Felix Feb 1 '17 at 16:07
  • $\begingroup$ @Felix Yep, in Acrobat CC 2017 it shows blue lines for me as well. In the built-in Preview program it shows white lines. $\endgroup$ – halirutan Feb 1 '17 at 16:09
2
+50
$\begingroup$

The issue is related to the opacity of the VertexColors. You can easily avoid it in this case by blending into white and not opaque.

data = Table[{x, (x - 5)^2 + 3}, {x, 0, 10}];
p1 = ListLinePlot[data, Filling -> {1 -> {15, {Blue, None}}}]
p1 = Normal@p1 /. 
   Polygon[x_] :> 
    Polygon[x, 
     VertexColors -> (Blend[{RGBColor[0, 0, 1], 
           RGBColor[1, 1, 1]}, #] & /@ Rescale[x[[All, 2]]])];
polygon = First[Cases[Normal@p1, _Polygon, Infinity]];
plt = Graphics[{EdgeForm[None], polygon}, AspectRatio -> 1]

enter image description here

(No hidden lines)

In case you inist having opacity, there are various methods suggested to work around the bug:

$\endgroup$
  • $\begingroup$ Very good answer. Indeed, the lines completely disappear. Note that the colors are different than in my question because the first color should be Blend[{RGBColor[0, 0, 1], RGBColor[1, 1, 1]}, 0.5] and not RGBColor[0,0,1]. It works perfect for my case, but sometimes you want the transparency option, hence I give the bounty to this one an accept halirutan's. $\endgroup$ – Felix Feb 1 '17 at 15:42
  • $\begingroup$ I guess you did not consider rasterization an option? $\endgroup$ – Johu Feb 1 '17 at 19:26
  • $\begingroup$ Only if everything else fails. I thought there should be a way to export polygons as vector graphics without defects. $\endgroup$ – Felix Feb 1 '17 at 19:28
1
$\begingroup$

Looks like a bug. One way around it is to export to png, re-import and re-export:

Export["test.png", %]
Export["test.pdf", Import["test.png"]]

Works on my Mac + 11.0.1.0.

$\endgroup$
  • 3
    $\begingroup$ But that's the same as rastering. $\endgroup$ – Felix Feb 1 '17 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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