4
$\begingroup$

Bug introduced in 11.3 or earlier

I am using Mathematica 11.3 on a Windows 10 computer. I plotted several data sets of mine in a ListLinePlot. While the .pdf file looks perfectly in the current Adobe Acrobat Reader DC version 2019.010.20098, the printout on three different printers and two different computers always shows weird additional lines crossing the whole image (see below).

Clipping error in pdf printout

This error seems to be related to: Mathematica Stack Exchange, question 129805. However, as I consider it to be very general (see below) and the question was not precise enough I opened up a new question. I think these errors result from a clipping error/bug in mathematica of the PlotRange command for large data sets outside the limits given.

Here is a minimum example given:

Let's calculate a simple normal distribution...

TestSet=Table[{x, PDF[NormalDistribution[0, 0.2], x]},{x, -100, 100, 0.1}];

Now we plot our data set only in a very small region...

SimpleExample=ListLinePlot[TestSet,PlotRange->{{-0.5, 1}, {0, 1}},ImageSize->400]

Subsequently, I exported the plot to a pdf file:

Export["Test.pdf", SimpleExample, ImageResolution -> 600];

While the .pdf file looks perfect, the scanned-in printout shows weird additional lines at the outer PlotRange limits. Apparently, the truncated edges of the data set plotted are arbitrarily connected with an invisible outer frame...

Clipping error in simple example

By trial-and-error I figured out that the problem must be related to the amount of data, which is outside the limits of the plot given by PlotRange. In a simple workaround I just chopped the data set down to only one next neighbor outside the PlotRange limits using the home-built function ChopLists:

    ChopLists[datalists_, xmin_, xmax_, ymin_, ymax_] :=(*ChopLists assumes that datalists is a list of sorted 2D-lists.*)
 Module[{xmin2Next, xmax2Next, ymin2Next, ymax2Next},
  (*If data outside the limits given by xmin, xmax,... exist, at least one data point (next neighbour) outside has to be still included by Chop List. Otherwise solid lines in ListLinePlot would stop before the frame boundary or might be falsely connected! E.g. truncated edges of a peak would be connected *)

  xmin2Next = Min[If[Length[Select[##, #[[1]] < xmin &]] > 0, Select[##, #[[1]] < xmin &][[-2, 1]], xmin] & /@datalists]; (*calculate 2nd next neighbour in each direction, if it exists*)
  xmax2Next = Max[If[Length[Select[##, #[[1]] > xmax &]] > 0, Select[##, #[[1]] > xmax &][[2, 1]], xmax] & /@datalists];
  ymin2Next = Min[If[Length[Select[##, #[[2]] < ymin &]] > 0, Select[##, #[[2]] < ymin &][[-2, 2]], ymin] & /@datalists];
  ymax2Next = Max[If[Length[Select[##, #[[2]] > ymax &]] > 0, Select[##, #[[2]] > ymax &][[2, 2]], ymax] & /@datalists];

  Select[#, xmin2Next < #[[1]] < xmax2Next && ymin2Next < #[[2]] < ymax2Next &] & /@datalists]
(*As the 2nd next neighbour is the limit, the next neighbour in each direction is included, if it exists*)

Now, if I apply ChopLists[...] to TestSet and use the same limits as for PlotRange...

SimpleExampleChopped=ListLinePlot[ChopLists[{TestSet}, -0.5, 1, 0, 1],PlotRange -> {{-0.5, 1}, {0, 1}}, ImageSize -> 400]

...and export to pdf again...

Export["Test.pdf", SimpleExampleChopped, ImageResolution -> 600];

...finally, the weird lines are gone:

By chopping the data set using ChopLists[] before plotting, the weird lines are gone

The same procedure also solved my initial problem: By chopping the data set using ChopLists[] before plotting, the weird lines are gone:

By chopping the data set using ChopLists[] before plotting, the weird lines are gone also in the initial more elaborate plot

My question is now: Is this a bug of PlotRange or does it result from the pdf export? Is this work-around needed or does any standard option exist to solve similar issues? Are there any options or combinations of them e.g. PlotRangeClipping, PlotRangePadding or ClippingStyle to prevent these clipping errors (simple combination of these three didn't work for me)?


UPDATE (26.03.2019) - Further testing on Windows and Mac

As suggested by @MassDefect I tested the same simple example also on a MAC (MAC OS 10.10.1 with Mathematica 9.0.1 and Adobe Reader 2018.011.2006). However, like him I was not able to reproduce the error. The printout from the .pdf file looked perfectly. I also copied the problematic .pdf file, which I had exported on my Windows 10 system, to the Mac. Surprisingly in the printout from the Mac no weird additional lines are visible and the printout is perfect.

Subsequently I copied both .pdf files, which were generated on the Windows 10 and the Mac to another different Windows 10 computer (Adobe Reader XI, Version 11.0.10) and printed them on another different printer. ...Again, the printed sheets from both .pdf files (Mac and Windows) showed the weird additional lines!

In conclusion: The problem must be related to the Windows .pdf format.


UPDATE (02.04.2019) - I received an answer from the wolfram support:

They also were able to reproduce the PlotRange/ghost lines behavior. A report is now forwarded to the development team. Hopefully it is fixed in a future Mathematica version. Chopping the data before plotting as I suggested seems to be an effective workaround.

$\endgroup$
  • $\begingroup$ It is the job of PlotRange to create a visual graphics object with... the specified PlotRange. If that's being done correctly in the visual representation of the notebook and then it looks incorrect on PDF Export, then the bug is in PDF Export. $\endgroup$ – user6014 Mar 24 at 23:57
  • 1
    $\begingroup$ @m_goldberg thanks for the editing. I was wondering why you deleted the tag bug? The plot of the simple example is intended to show a Gaussian peak, which is does not. Instead the lines are arbitrarily connected with the outer frame. Can you reproduce the same behavior? Isn't this clearly a bug? Especially, as a similar problem was already reported earlier in question 129805. Thanks for an answer in advance. $\endgroup$ – Martin L Mar 25 at 8:34
  • 1
    $\begingroup$ Read about how the bugs tag is special by following this link $\endgroup$ – m_goldberg Mar 25 at 15:12
  • 1
    $\begingroup$ Could not reproduce on macOS 10.14.3 with MMA 11.3. I used both Preview and Adobe Acrobat 2019.010.20098 and the printouts were fine. Might be something that only affects Windows users? It seems especially odd that the printout is different from the PDF. $\endgroup$ – MassDefect Mar 25 at 16:10
  • 1
    $\begingroup$ @MassDefect I agree with the conclusion that it could be a Windows issue; the question I posed was based on a Mathematica instance that was running on Windows7 $\endgroup$ – Nonsingular Mar 26 at 14:56

Your Answer

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

Browse other questions tagged or ask your own question.