2
$\begingroup$

I use the following code to generate and export a simple combined figure with an epilog of the long horizontal arrow.

inten = (x y (z^3 + 0.2))/(x^2 + y^2 + z^2 + 0.01);
max = 1; zlst = Range[2, -2, -4/(5 - 1)];
frameticks = {-0.5, 0.5};

plot0 = Table[
   ContourPlot[
    inten /. z -> zlst[[-i]], {x, -max, max}, {y, -max, max}, 
    FrameTicks -> {{frameticks, None}, {frameticks, None}}, 
    ImagePadding -> {{Automatic, Automatic}, {23, 36}}, 
    ImageSize -> 160], {i, Length@zlst}];
plot = GraphicsRow[plot0, 
  Epilog -> {Gray, Thickness[0.01/3], Arrowheads[0.015], 
    Arrow[{Scaled[{0, 0.96}], Scaled[{0.94, 0.96}]}]}, 
  ImageSize -> 1000]

Export["Fig_try.pdf", plot]

It looks good in the front end, but is weirdly damaged in two aspects in the exported pdf.

  1. The arrowhead at the top right corner is cut out;
  2. There appear many glitches around the boundary of each plot.

From the comments received, it seems not limited to my machine or to PDF format. Any remedy or workaround?

enter image description here

$\endgroup$
12
  • $\begingroup$ Please include your data (or fake sample data) so that we can run your code, otherwise it may be difficult to troubleshoot. A shot in the dark: Does using Row instead of GraphicsRow improve the situation at all? $\endgroup$
    – MarcoB
    Commented Jun 18, 2022 at 13:29
  • $\begingroup$ @MarcoB The code is self-contained. And I need GraphicsRow instead of Row to add various epilogs. $\endgroup$
    – xiaohuamao
    Commented Jun 18, 2022 at 13:35
  • $\begingroup$ This seems like a bug—it happens with other vector graphics formats like .svg and .eps, and isn't specific to the .pdf export. I'm guessing you want vector graphics—but if not, then exporting to .png (with e.g. Export["Fig_try.png", plot, ImageResolution -> 600]) seems to work. (There are still some misalignments with the contour lines starting too early and ending too late, but if you look closely, you'll notice these are already present in the notebook itself!) $\endgroup$
    – thorimur
    Commented Jun 18, 2022 at 23:39
  • $\begingroup$ @thorimur Thanks for the info on other formats. Yes, I want vector graphics basically. BTW, I don't see any contour lines overplotted in my front end as far as I've zoomed in. $\endgroup$
    – xiaohuamao
    Commented Jun 19, 2022 at 0:18
  • $\begingroup$ Oh, that's good! maybe it's a version difference or an OS difference. As for getting vector graphics...hmm. might be worth it to contact wolfram support about it. There also might be ways to refine the shapes or translate them to a format that's more amenable to svg export. By examining FullForm, we see that the regions of the plots are currently GraphicsComplexes of GraphicsGroups of Polygons. I wonder if converting them to some other form, like meshes(?), or messing with their vertex-related options would have any effect on the export. $\endgroup$
    – thorimur
    Commented Jun 19, 2022 at 0:26

1 Answer 1

1
$\begingroup$

Following the chat above, here I post a workaround. The boundary glitches are solved by cleanContourPlot, as suggested by @Michael E2. The arrowhead is a bit trickier. But as suggested by @thorimur (who probably will not post an answer), splitting the command of arrow and line and making the arrow as short as an arrowhead can work, which means we replace the real long Arrow with a long Line and a very short Arrow. This arrow issue seems to be a bug to me.

inten = (x y (z^3 + 0.2))/(x^2 + y^2 + z^2 + 0.01);
max = 1; zlst = Range[2, -2, -4/(5 - 1)];
frameticks = {-0.5, 0.5};

plot0 = Table[
   cleanContourPlot@
    ContourPlot[
     inten /. z -> zlst[[-i]], {x, -max, max}, {y, -max, max}, 
     FrameTicks -> {{frameticks, None}, {frameticks, None}}, 
     ImagePadding -> {{Automatic, Automatic}, {23, 36}}, 
     ImageSize -> 160], {i, Length@zlst}];
plot = GraphicsRow[plot0, 
  Epilog -> {Gray, Arrowheads[0.015], 
    Arrow[{Scaled[{0.93, 0.96}], Scaled[{0.94, 0.96}]}], Gray, 
    Thickness[0.01/3], 
    Line[{Scaled[{0, 0.96}], Scaled[{0.93, 0.96}]}]}, 
  ImageSize -> 1000]

Export["Fig_try.pdf", plot]
$\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.