2
$\begingroup$
$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:

enter image description here

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

enter image description here

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

enter image description here

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.

$\endgroup$
  • 2
    $\begingroup$ Put the ImageSize specification within the Plot[] function, not within the Export call. $\endgroup$ – David G. Stork May 12 '17 at 16:34
  • $\begingroup$ 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! $\endgroup$ – barrycarter May 12 '17 at 17:04
2
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Thanks. Actually Export does accept ImageSize, and uses it to determine the size of the canvas. It works for most plots, but not legended plots. $\endgroup$ – barrycarter May 12 '17 at 17:14

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.