5
$\begingroup$

Bug introduced in 11.2 or earlier and persisting through 12.0


I placed a framed PlotLegend and it works just fine in the notebook, but after exported to PDF the legend frame disappeared.

Here's the data as example.

list={{{2, 2, 2, 2}, {10.9323, 10.9323, 10.9323, 
   10.9323}, {4.233}}, {{21.8656, 358.919}, {21.9156, 
   103.891}, {21.9656, -21.9377}, {22.0156, -52.9273}, {22.0656, 
   -32.5523}, {22.1156, 9.22699}, {22.1656, 54.4444}, {22.2156, 
   94.4478}, {22.2656, 124.699}, {22.3156, 143.77}, {22.3656, 
   152.507}, {22.4156, 153.301}, {22.4656, 147.381}, {22.5156, 
   136.734}, {22.5656, 122.683}, {22.6156, 107.942}, {22.6656, 
   92.2245}, {22.7156, 76.9519}, {22.7656, 63.8046}, {22.8156, 
   51.9468}, {22.8656, 42.5287}}}

And the plot function

fig = 
     ListPlot[Select[Re@#[[2]], # \[Element] Reals &] & /@ #, 
      PlotRange -> {{Min[#1] - 0.1, 
           Max[#2] - 
            0} &@(Sequence @@ (Transpose[{First[#[[2]]][[1]] - 0.1, 
                Last[#[[2]]][[1]]} & /@ #])), All}, Joined -> True, 
      ImageSize -> 500, 
      PlotLegends -> 
       Placed[LineLegend[(ToString[#[[1, 1, 1]]] <> "+" <> 
             ToString[#[[1, 1, 2]]] <> "\[Rule]" <> 
             ToString[#[[1, 1, 3]]] <> "+" <> 
             ToString[#[[1, 1, 4]]]) & /@ #, 
         LegendLayout -> {"Column", 1}(*,LegendMarkerSize\[Rule]20*), 
         LegendMargins -> 3, LegendFunction -> "Frame"], {Right, 
         Top}], Frame -> True]&@ {list}

and now export

Export["~/Desktop/3.pdf", fig]

It's probably not caused by the exporting format because I tried eps but had no effect.

The figure before export:

The figure before export

The figure after export:

The figure after export

BTW my MMA version is 11.2.

$\endgroup$
2
$\begingroup$

Export is clearly not working correctly. One thing that works for me is:

  1. click the graphic in your notebook to select it
  2. right-click to bring up the context menu
  3. "Save Graphic As..." and choose PDF.

This preserves the frame around the legend.

You could also try my autoLegend function from this answer. It's from the bad old days before PlotLegends were introduced in Mathematica, but it still works fine for me, and also exports properly.

$\endgroup$
0
$\begingroup$
 Export["TestPlot18" <> #, fig, ImageResolution -> 300] & /@ {".pdf", ".png", ".jpg"}

poly

$\endgroup$
  • $\begingroup$ I don't understand. I presume the only difference is ImageResolution? But I added it and it didn't work. Well, png works but that's the same as Rasterize I think? And it would looks really bad inside a pdf file, I mean, with latex. $\endgroup$ – Turgon Mar 12 '18 at 14:04
  • $\begingroup$ But, we found that its works well for pdf and jpg same ag png. We can sent you if you want. $\endgroup$ – Gopal Verma Mar 12 '18 at 14:53
  • $\begingroup$ That's weird. What's your MMA version? And thank you for your kindness but I want to solve this problem, at least find out what went wrong. $\endgroup$ – Turgon Mar 12 '18 at 15:28
  • $\begingroup$ I am using MMA 10. There is typo in your list data (inserted / at {22.0656, \-32.5523} this point) . I found only one plot. as shown above. $\endgroup$ – Gopal Verma Mar 12 '18 at 15:53
0
$\begingroup$

You can click before the figure (Fig). Then write Export["Fig is here",eps]. Using this method you can export all parts of your figure.

$\endgroup$
  • $\begingroup$ The legend frame would become "Unevaluated["the legend"]". $\endgroup$ – Turgon Sep 4 '19 at 6:28
  • $\begingroup$ I cannot run your fig. There are some errors. $\endgroup$ – Perfect Fluid Sep 5 '19 at 8:38
  • $\begingroup$ There was an extra line break last line, it should be fine now. $\endgroup$ – Turgon Sep 6 '19 at 6:43

Your Answer

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

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