The code below plots and exports to a PDF file. As one can see, there is a clear difference between the plotted line thickness in the notebook (left) and in the PDF snapshot (right). This is a sister question of this thread. The phenomenon looks similar but the context/workaround is not that related at least apparently.

mydata = 
  Table[Sin[x + y^2], {x, 0, \[Pi], \[Pi]/100}, {y, 
    0, \[Pi], \[Pi]/100}];
plot = With[{blplot = 
    ContourPlot[x^2 + y^2 == 0.06^2, {x, -0.1, 0.1}, {y, -0.1, 0.1}, 
     ContourStyle -> {Blue, Dashed, Thickness[0.013]}], 
   mainplot = 
    ListDensityPlot[mydata, DataRange -> 0.08 {{-1, 1}, {-1, 1}}, 
     FrameTicks -> {{0.08 {-1, 1}, None}, {0.08 {-1, 1}, None}}, 
     FrameTicksStyle -> Directive[15], PlotRange -> Full]}, 
  Show[mainplot, blplot, ImageSize -> 205]]
Export[FileNameJoin[{NotebookDirectory[], "Test2.pdf"}], plot, 
  ImageResolution -> 300];

enter image description here

And we have very similar observations to those in the linked question.

  • There is some threshold thickness between 0.013 and 0.014, where the PDF line thickness suddenly changes.
  • Double the imagesize may occasionally get this issue away, but this is not what is wanted. For other reasons like file size and screen size, I need to keep such an image size.
  • Right-clicking the image and saving it as PDF is not a desired solution, either.
  • Tuning ImageResolution does not help. Removing this option sometimes may get it right, but in other more complicated plots this will make the PDF file outrageously large or just freeze the program.

Is there any remedy for this?


Using AbsoluteThickness helps for replacing Thickness[0.013] by AbsoluteThickness[0.013 imagesize], but does not work for (relative) Thickness below or equal to 0.01.


Thanks to the comments by @Michael E2, the cause of this whole thickness issue is believed to be 'VertexColors' used by ListDensityPlot. However, it is not yet clear how to work this around in the present case.

  • 1
    $\begingroup$ Try AbsoluteThickness[t*i] where t is the relative thickness and i is the ImageSize. -- I'm pretty sure this is the same bug (the particular renderer invoke). That DensityPlot invokes it instead of VertexColors does not distinguish this significantly to my mind. E.g. FreeQ[plot, VertexColors] shows that DensityPlot is using VertexColors. And Export[FileNameJoin[{"/tmp", "Test2.pdf"}], DeleteCases[plot, _[VertexColors, _List], Infinity], ImageResolution -> 300] yields a PDF with appropriate thickness. $\endgroup$
    – Michael E2
    Jun 21, 2023 at 14:43
  • $\begingroup$ @MichaelE2 Thank you. Similar to here, AbsoluteThickness does not work below 0.01 here. And the DeleteCases command gives a PDF losing the entire plot except the dashed line. (Or maybe you only intend to show the relevance to VertexColors?) $\qquad\qquad\qquad\qquad\qquad\qquad$ In any case, we still need a workaround here. $\endgroup$
    – xiaohuamao
    Jun 22, 2023 at 3:07
  • $\begingroup$ "Or maybe you only intend to show the relevance to VertexColors?" Right. :) $\endgroup$
    – Michael E2
    Jun 22, 2023 at 5:11
  • $\begingroup$ ".... does not work below 0.01" -- This is an old bug with PDF rasterization, I believe. I've run into it, pre-Stackexchange, IIRC. Something like less than AbsoluteThickness[2.5] $\endgroup$
    – Michael E2
    Jun 22, 2023 at 5:18
  • $\begingroup$ @MichaelE2 'not working below 0.01 is an old bug with PDF rasterization' I still doubt it. In the earlier question, as long as we do not use VertexColors, the PDF works fine all the way down to the minimal recognizable thickness, far below AbsoluteThickness[2.5]. $\endgroup$
    – xiaohuamao
    Jun 22, 2023 at 6:22


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.