Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Mathematica 9.0.1, and I have problems with PlotLegends breaking the ImageSize directive.

I defined

cm = 72 / 2.54;

to work with centimeters. I would like an output PDF with a width of, say, 9 cm.

  Exp[-4 f] /. {{f -> t}, {f -> t^2}}], {t, 0, 3}, 
  BaseStyle -> {FontSize -> 11, AbsoluteThickness[1.5]}, 
  PlotStyle -> {Blue, Red}, 
  AxesLabel -> {"t"},  
  PlotLabel -> "Negativity", 
  ImageSize -> 9 cm,  
  PlotLegends -> Placed[{"OU", "FBM"}, {.8, .5}]]
Export["Neg_long_OU_FBM.pdf", %];

With this command, I obtain a PDF with size 6.48 × 4.31 cm. If I remove the PlotLegends option, I get the correct width of 9 cm. If I leave PlotLegends without the Placed directive (the legend is placed at the right of the Plot), I get 9.42 × 4.38 cm.

Is this an expected behavior? How can I produce an output PDF with a 9 cm width and the legend inside the plot?

share|improve this question
Not a complete answer, but using Export["Neg_long_OU_FBM.pdf", %, ImageSize -> 9 cm]and not setting the ImageSize in the Plot gets you much closer. – chuy Apr 7 '14 at 14:42
I think that this is just a coincidence, as the output of Plot (without setting ImageSize) has a size of 9.15 cm. In fact I obtain the same result with Export["...", %], Export["...",%, ImageSize -> 9 cm ] or Export["...", %, ImageSize -> 2 cm] – Pincopallino Apr 7 '14 at 15:14
Ah very true indeed. – chuy Apr 7 '14 at 15:37
Problem still there in V 10.1... – Alexey Bobrick Apr 1 '15 at 12:20
up vote 3 down vote accepted

This might help. Here I have a helper function to make the legend into an Inset:

plot = Plot[Evaluate[Exp[-4 f] /. {{f -> t}, {f -> t^2}}], {t, 0, 3}, 
   BaseStyle -> {FontSize -> 11, AbsoluteThickness[1.5]}, 
   PlotStyle -> {Blue, Red}, AxesLabel -> {"t"}, 
   PlotLabel -> "Negativity", 
   PlotLegends -> Placed[{"OU", "FBM"}, {.8, .5}], ImageSize -> 9 cm];

makeInset[plot_Legended] := 
    Inset[plot[[2, 1, 1]], Scaled[plot[[2, 1, 2]]]]]}]

and then wrap plot with this function:

Export["Neg_long_OU_FBM.pdf", makeInset[plot]];
share|improve this answer
This workaround works like charm! I just had to slightly modify the Part of like this makeInset[plot_Legended] := Show[{plot[[1]], Graphics[Inset[plot[[2, 1, 1]], Scaled[plot[[2, 1, 2]]]]]}] to make it work with my code. Thank you! I'm still wondering if there are cleaner solutions! – Pincopallino Apr 7 '14 at 16:12
Yes, sorry I see I was using a slightly different plot. I will correct this. – chuy Apr 7 '14 at 16:15

The problem is still present in Mathematica 10.3. and it appears also if plots are combined with Grid (or Column, ...) before being exported to a pdf. So maybe PlotLegend uses internally a Grid-like function.

Interestingly, the scaling factor 6.48 cm / 9 cm = 0.72 matches exactly the Magnification value of the default Printout environment (Format > Edit Stylesheet... > Default.nb > section Style Environment Names > select Printout > open Option Inspector > search Magnification). Therefore, this problem can be solved by choosing

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

the Working environment according to

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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