3
$\begingroup$

I have been trying to export an image (not the image below) with a legend to a pdf format for a publication (Mathematica 11.0.1). Unfortunately everything I have tried exports a version of the graphic where the legend is moved somewhere. I have tried looking into this (Szabolcs answer), this and have looked at the discussion here, but can't get it to work.

Here is a minimal example

data = Table[1/(1 - x^2), {x, 2, 11, 1}];
points = Table[x, {x, 2, 11, 1}];
pp = ListPlot[Transpose[{points, data}], PlotMarkers -> Automatic, 
  PlotLegends -> 
   Placed[PointLegend[{"Equation"}, 
     LegendFunction -> (Framed[#, Background -> LightBlue, 
         FrameStyle -> Directive[Black, Thick]] &), 
     LegendMarkerSize -> 12, 
     LegendLabel -> 
      Placed["Expr", Left, Rotate[Style[#, 14], 90 Degree] &], 
     LabelStyle -> Directive[12], LegendMargins -> 0], {0.19, 0.3}]]

LegEx

Exporting it with

Export["SomeDestination.pdf", pp, ImageResolution -> 600]

Leads to

enter image description here

(This is also the result of right-clicking on the graph in the notebook (the first provided image here) and selecting "Save Graphic as")

I have also tried doing

cm = 72/2.54;
image = Rasterize[Show[pp, ImageSize -> 126/10 cm], "Image", 
   ImageResolution -> 600];
Export["SomeDestination.pdf", 
 Show[image, ImageSize -> 126/10 cm], ImageResolution -> 600]

which gives

enter image description here

So we have three different images.

This is all done under

In[38]:= Options[$FrontEnd, {PrintingStyleEnvironment, 
  ScreenStyleEnvironment}]

Out[38]= {PrintingStyleEnvironment -> "Working", 
 ScreenStyleEnvironment -> "Working"}

All I want is to export as a pdf what I see in the notebook.

P.S. I would also be happy to see a solution where the image is not exported to a pdf, but to any other format.

$\endgroup$
4
  • $\begingroup$ You can also see that the tick marks are completely shrunk to zero in the rasterized export. If I were you I'd just take the orange highlighted first output you posted, and in that highlighted state right-click on it to get the contextual Save Graphic As... menu. That allows you to save as PDF in the most faithful way. $\endgroup$
    – Jens
    Commented Jul 11, 2017 at 17:56
  • $\begingroup$ I tried that and gives the same result as the second provided image in my question - i.e. just doing it with Export. I also updated my question to include that information $\endgroup$ Commented Jul 11, 2017 at 21:46
  • $\begingroup$ Have you tried including ImageSize in your original ListPlot? $\endgroup$ Commented Jul 12, 2017 at 6:30
  • $\begingroup$ ImageSize and ImageResolution are two different things, aren't they? The former will just make the image bigger (more pixels), but the density of points on the plot will be the same, whereas the latter increases the dpi (dots per inch), while keeping the pixel size, hence making a sharper image. I need a very high quality plot (600 dpi or higher by requirements), but not a big plot $\endgroup$ Commented Jul 12, 2017 at 8:42

0

Your Answer

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

Browse other questions tagged or ask your own question.