4
$\begingroup$

I am experiencing problems with exporting figures such as combinations of ContourPlot and ComplexListPlot. As an example, when zooming into the resulting pdf of the plot

Show[ComplexListPlot[{0.4 + 0.2 I}, 
  PlotMarkers -> {{Graphics[Triangle[{{{0, 0}, {1, 1.6}, {2, 0}}}]], 
     0.03}}]]
Export["test.pdf", %];

this gives the following picture.

The top part is cut off for no apparent reason. When such PlotMarkers are combined with more complicated Figures, they get arbitrarily disfigured (ignore the gray strip):

This should depict a Triangle, and there are similar problems for simpler Graphics such as Rectangle or Disk. An alternative to PlotMarker is given in this answer, which for simple plots works but in combination with other plots shows similar effects. The result is not dependent on the way the Figure is saved (either with "Save Graphic as" or Export), and seems to be independent also on the file type. I am running Mathematica 12.3. Any help is much appreciated.

$\endgroup$
6
  • $\begingroup$ One way around this is to Rasterize your graphic before exporting: Export["test.pdf",Rasterize[%, ImageSize -> Full]]; you can increase the resolution if necessary $\endgroup$ Commented Jun 21, 2021 at 19:42
  • $\begingroup$ Thank you, it works but unfortunately the image quality is significantly lower (even with increasing the ImageResolution). Perhaps you have other ideas? $\endgroup$
    – El Rafu
    Commented Jun 21, 2021 at 21:03
  • $\begingroup$ Have you tried this? Export["test.pdf", Rasterize[%, ImageSize -> Full, ImageResolution -> 600]]; That created a very crisp image for me $\endgroup$ Commented Jun 21, 2021 at 22:03
  • $\begingroup$ Yes it does give a relatively sharp image, however with my plots the files get huge and take a long time to load in a PDF viewer. I am really trying to circumvent this if possible. $\endgroup$
    – El Rafu
    Commented Jun 21, 2021 at 22:26
  • $\begingroup$ Have you tried constructing the polygons without using the built-in primitives? $\endgroup$ Commented Jun 22, 2021 at 2:19

1 Answer 1

3
$\begingroup$

Basically you are facing the problem described here. The simplest workaround is to evaluate

SetOptions[$FrontEndSession, PrintingStyleEnvironment -> "Working"]

before exporting. Now it works as expected:

ComplexListPlot[{0.4 + 0.2 I}, 
  PlotMarkers -> {{Graphics[Triangle[{{{0, 0}, {1, 1.6}, {2, 0}}}]], 0.03}}];
Export["test.pdf", %] // SystemOpen

screenshot

Note however that your plot marker is misplaced:

Show[ComplexListPlot[{0.4 + 0.2 I}, 
       PlotMarkers -> {{Graphics[Triangle[{{{0, 0}, {1, 1.6}, {2, 0}}}]], 0.2}}], 
     ComplexListPlot[{0.4 + 0.2 I}, PlotStyle -> Red]]

output

You see that the center of the triangle is misplaced. Here is a way to place your plot marker correctly:

marker = Triangle[{{{0, 0}, {1, 1.6}, {2, 0}}}];
markerCentroid = RegionCentroid[marker];
markerBounds = RegionBounds[yourMarker];
markerPlotRange = 
  Transpose[{markerCentroid - #, markerCentroid + #} &[
    Max /@ Abs[markerBounds - markerCentroid]]];
pl = Show[
  ComplexListPlot[{0.4 + 0.2 I}, 
   PlotMarkers -> {{Graphics[marker, PlotRange -> markerPlotRange, 
       PlotRangePadding -> 1], 0.5}}], 
  ComplexListPlot[{0.4 + 0.2 I}, PlotStyle -> Red]]

output2

This plot will export correctly even with the default settings for PrintingStyleEnvironment:

SetOptions[$FrontEndSession, PrintingStyleEnvironment -> Inherited]
Export["test.pdf", pl] // SystemOpen

screenshot

Another method is to apply the AlignmentPoint option:

marker = Triangle[{{{0, 0}, {1, 1.6}, {2, 0}}}];
markerCentroid = RegionCentroid[marker];
Show[ComplexListPlot[{0.4 + 0.2 I}, 
        PlotMarkers -> {{Graphics[marker, AlignmentPoint -> markerCentroid, 
                                  PlotRangePadding -> 1], 0.5}}], 
     ComplexListPlot[{0.4 + 0.2 I}, PlotStyle -> Red]]

output

All these problems can be easily avoided with ResourceFunction["PolygonMarker"]:

SetOptions[$FrontEndSession, PrintingStyleEnvironment -> Inherited]

Show[ComplexListPlot[{0.4 + 0.2 I}, 
        PlotMarkers -> {Graphics[
           ResourceFunction["PolygonMarker"]["Triangle", Scaled[0.2]]]}], 
     ComplexListPlot[{0.4 + 0.2 I}, PlotStyle -> Red]]
Export["test.pdf", %] // SystemOpen

screenshot

$\endgroup$

Your Answer

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

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