6
$\begingroup$

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 and in the PDF snapshot.

d1 = Cos[x] + Cos[z] - 2; x0 = 0; z0 = \[Pi]/2; SSregion[x_, z_] = d1^2 - 1 < 0; bleqn = d1^2 - 1 == 0; twopts = {{x0, z0}, {x0, -z0}}; plotTP = {PointSize[0.03], Point[twopts, VertexColors -> {Black, Black}]}; lines = {{0.4, 0.6}, {2.4, 0.6}}; thickness1 = 0.01; thickness2 = 0.01; plotreg = RegionPlot[SSregion[x, z], {x, -\[Pi], \[Pi]}, {z, -\[Pi], \[Pi]}, BoundaryStyle -> Directive[Thickness[thickness1], Dashed], FrameLabel -> {"x", "z"}, FrameTicksStyle -> 18, LabelStyle -> 22, Epilog -> {plotTP}, ImageSize -> 255]; plotreg = Show[plotreg, Graphics[{Black, Thickness[thickness1], Dashed, Line[lines]}]] Export[FileNameJoin[{NotebookDirectory[], "Test.pdf"}], plotreg, ImageResolution -> 300]; 

enter image description here enter image description here

Several observations:

  • There seems to be some threshold thickness between 0.01 and 0.011, 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-click the image and save it as PDF sometimes may get it right, but not a desired solution, either. For instance, sometimes I need to use Grid (rather than GraphicsGrid) for multiple figures, which does not accept such a workaround.
  • 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?

$\endgroup$
3
  • $\begingroup$ Happens also in a simple PolarPlot $\endgroup$ Commented Jan 7, 2024 at 15:56
  • $\begingroup$ @atapaka You're wrong about michealE2's code. Here's a screenshot of what I get for thickness1 = 0.004, 0.008, and 0.012: i.sstatic.net/BCvT3.png That's what I expect to get. (I think the thichness2 was supposed to be edited out, since the code works and it's unused.) $\endgroup$ Commented Jan 9, 2024 at 0:45
  • $\begingroup$ @Goofy It is an interesting problem, I will soon post a topic towards that since this seems to be platform specific and format specific. e.g. for PNG: Mac - does not work, linux, works, Windows, idk. For EPS does not seem to work on linux either. $\endgroup$ Commented Jan 11, 2024 at 18:45

2 Answers 2

3
$\begingroup$

This is a bug. To work around it, remove the VertexColors -> {Black, Black} specification (which causes it to use a different renderer).

$\endgroup$
5
  • $\begingroup$ Sorry, this does not solve the problem. 1) It removes an option needed for some other purpose (e.g., a color different from black), hence the MWE in its present form. 2) On my computer, it gives weird meshes in the shaded region. 3) In my attempt at my real problem, which is a slightly different shaded shape combined with other things, the weird meshes go away but it still suffers from the same thickness problem. Therefore, I strongly believe this option is not the culprit. $\endgroup$ Commented Jun 21, 2023 at 1:32
  • $\begingroup$ The flaw is in the 3D renderer (which is used whenever VertexColors is specified). That is the only way that I could find that works around the issue. $\endgroup$ Commented Jun 21, 2023 at 10:54
  • $\begingroup$ Thanks a lot. I tried again and found that it indeed works and one can use other ways to specify the color of Point. OK. This is indeed a magic workaround. I will accept if no other answer in one or two days. BTW, there is another very similar case. Do you happen to have any clue? $\endgroup$ Commented Jun 21, 2023 at 14:26
  • $\begingroup$ It's the same. ListDensityPlot probably spec'd VertexColors. $\endgroup$ Commented Jun 21, 2023 at 16:31
  • $\begingroup$ If only you would have any workaround for that case. I haven't found one yet. $\endgroup$ Commented Jun 22, 2023 at 3:18
2
$\begingroup$

Here is another workaround: Use AbsoluteThickness[], calculating the thickness as the relative thickness times the image width.

d1 = Cos[x] + Cos[z] - 2; x0 = 0; z0 = \[Pi]/2; SSregion[x_, z_] = d1^2 - 1 < 0; bleqn = d1^2 - 1 == 0; twopts = {{x0, z0}, {x0, -z0}}; plotTP = {PointSize[0.03], Point[twopts, VertexColors -> {Black, Black}]}; lines = {{0.4, 0.6}, {2.4, 0.6}}; thickness1 = 0.01; thickness2 = 0.01; imagesize = 255; (***) plotreg = RegionPlot[SSregion[x, z], {x, -\[Pi], \[Pi]}, {z, -\[Pi], \[Pi]}, BoundaryStyle -> (***) Directive[AbsoluteThickness[thickness1*imagesize], Dashed], FrameLabel -> {"x", "z"}, FrameTicksStyle -> 18, LabelStyle -> 22, Epilog -> {plotTP}, ImageSize -> imagesize (***) ]; plotreg = Show[plotreg, Graphics[{Black, AbsoluteThickness[thickness1*imagesize], (***) Dashed, Line[lines]}]] Export[FileNameJoin[{$TemporaryDirectory, "Test.pdf"}], plotreg, ImageResolution -> 300]; 

$\endgroup$
2
  • $\begingroup$ Thanks. This does not really get rid of the issue. It only lowers the threshold thickness between 0.008 and 0.009. Once we plot with 0.008, the issue recurs. $\endgroup$ Commented Jun 22, 2023 at 2:57
  • $\begingroup$ Does not work at all. $\endgroup$ Commented Jan 7, 2024 at 15:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.