# Using PlotLegends makes plot much smaller when exported

\$Version
11.1.0 for Linux x86 (64-bit) (March 13, 2017)

(* a simple plot, turns out nice *)

t1 = Plot[x^2,{x,-5,5}];
Export["/tmp/test1.png", t1, ImageSize -> {800,600}];

(* let's add a legend, turns out small *)

t2 = Plot[x^2,{x,-5,5},PlotLegends -> {"x^2"}]
Export["/tmp/test2.png", t2, ImageSize -> {800,600}]

(* if we make image bigger, plot still turns out small *)

t3 = Plot[x^2,{x,-5,5},PlotLegends -> {"x^2"}]
Export["/tmp/test3.png", t3, ImageSize -> {800*2,600*2}]


test1.png from the above looks very nice and uses up the entire 800x600 canvas:

test2.png's plot uses up only a fraction of the 800x600 canvas:

test3.png has a larger canvas (2 times larger in each direction), but the plot is exactly the same size as in test2.png:

I'd at least expect it to be two times bigger in each direction, even if it didn't use up the entire 1600x1200 canvas. My hope for test3.png was to create a larger image that didn't fill the canvas and then use ImageMagick to crop.

Why does this PlotLegends problem occur and how can I fix it?

I've skimmed similar questions on this site, but I don't think any address this issue exactly. Several of these questions suggest "homebrew" solutions, which I'd prefer to avoid if at all possible.

• Put the ImageSize specification within the Plot[] function, not within the Export call. – David G. Stork May 12 '17 at 16:34
• Wow, that was easy, thanks! I didn't even realize you get set imagesize before conversion. Write that as an answer and I'll approve it, thanks! – user1722 May 12 '17 at 17:04

Put ImageSize specification within the Plot[] function, not within the Export call.