1

Bug introduced in 12 or earlier and persisting through 13.1.0 [CASE:4899765]


How can I remove the outline in my export PDF here which seems to be caused by the overlapping of the shape and the grid lines?

enter image description here

It doesn't seem to show on the Mathematica image (or just because I couldn't zoom in enough) but when I exported PDF and zoom in I can see it.

polygon = {{1, 1}, {3, 1}, {4, 2}, {2, 4}, {1, 3}}
image = ListLinePlot[polygon, 
    GridLines -> {Range[1, 5, 1/2], Range[0, 5, 1/2]}, 
    PlotRange -> {{1, 5}, {0, 5}}, Filling -> {1 -> Axis}, 
    FillingStyle -> Directive[Opacity[0.2], Orange], 
    GridLines -> {Range[1, 5, 1], Range[1, 5, 1]}, ImageSize -> 250, 
    AspectRatio -> 1, 
    Frame -> {{None, Automatic}, {Automatic, None}}] /. _Line -> 
    Sequence[];
Export["image.pdf", image]

This is the output in my 13.0.1 version which is even worse than the 12.1 version. I'm going to check for the update.
I checked for the update but unfortunately we here we don't have the latest version for support. Is there any way to work around this?

enter image description here

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
hana
  • 2,388
  • 5
  • 19
  • @cvgmt I think I have the same problem in my 13.1 version. The above is from 12.1.1 in my PC but with I had the same problem yesterday in a 13.1 version on a different computer. – hana Jun 30 '22 at 04:49
  • Anyway I'll check it again when I get to my 13.1 version. Is there any fix for the 12.1? – hana Jun 30 '22 at 04:55
  • You can make the grid lines non-transparent, and apply the option "GridLinesInFront" (search for it on the site). – Alexey Popkov Jun 30 '22 at 07:45
  • @AlexeyPopkov what do you mean non-transparent grid lines? What seems to be opposite with what I'm trying to do now. I want to show the grid lines but I don't want to show the outline around the orange region as in the image above. – hana Jun 30 '22 at 07:56
  • You question formulation is a bit misleading. If the problem is not with grid lines, but with the region, you could try to adjust the style of the region boundary using the PlotStyle option. – Alexey Popkov Jun 30 '22 at 08:13
  • @AlexeyPopkov I don't think so? I did remove the region boundary with _Line -> Sequence[] already but somehow it still appears when I export to pdf. – hana Jun 30 '22 at 08:18
  • This is a known bug. https://mathematica.stackexchange.com/q/262617/280 – Alexey Popkov Jun 30 '22 at 08:41
  • With version 13.1.0 on Win10 x64 I reproduce the bug: https://i.stack.imgur.com/bH8ZR.png – Alexey Popkov Jun 30 '22 at 09:36
  • @AlexeyPopkov likely so but I'll check if it works for my case. – hana Jun 30 '22 at 09:53

1 Answers1

2

UPDATE

Here is a universal version of polygon2FilledCurve which should work correctly independently of the presence of GraphicsComplex inside of Graphics:

polygon2FilledCurve = # /. 
     g_GraphicsComplex :> (g /. {
         Polygon[pts : {{__Integer} ..}] :> FilledCurve /@ Thread[Line[pts]],
         Polygon[pts : {__Integer}] :> FilledCurve[Line[pts]]}) /.
    {Polygon[pts : {_?(MatrixQ[#, NumericQ] &) ..}] :> FilledCurve /@ Thread[Line[pts]],
     Polygon[pts_ /; MatrixQ[pts, NumericQ]] :> FilledCurve[Line[pts]]} &;

(original version below works incorrectly in more complicated cases than the one given in the OP, as was found here.)


Original answer

Your problem is not related to grid lines, it is just the known bug with exporting Polygon primitive to PDF format. The workaround is to represent the Polygon as a FilledCurve object which doesn't suffer from the bug:

polygon2FilledCurve = # /. {
     Polygon[pts_ /; Depth[pts] == 3] :> FilledCurve[Thread[Line[pts]]],         
     Polygon[pts_ /; Depth[pts] == 2] :> FilledCurve[Line[pts]]} &;

Export["image.pdf", polygon2FilledCurve[image]] // SystemOpen

Here is how exported figure is rendered by Adobe Acrobat:

screenshot

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368