2
$\begingroup$

I need to place a complete plot (with axes, graphs etc.) on a larger canvas (or expand the canvas for an existing graph) but I cannot find the correct commands/syntax for it. Anyone that can point me in the right direction?

E.g. I have a graph that is 500x500 px

 H = Plot[{x, Sqrt[x]}, {x, 0, 2}, ImageSize -> 500, AspectRatio -> Full]

but when I export this to JPEG file I want the canvas to be 600 high and 1340 wide, with the graph centered in the middle. Is this possible? TIA.

$\endgroup$
2
  • $\begingroup$ maybe ImageMargins:, e.g. Plot[{x, Sqrt[x]}, {x, 0, 2}, ImageSize -> 200, AspectRatio -> 1, ImageMargins -> Scaled[.2]]? $\endgroup$
    – kglr
    Jul 28 '18 at 15:30
  • $\begingroup$ ... or ImageMargins -> {{#, #} &@(1340 - 500)/2, {#, #} &@(600 - 500)/2}? $\endgroup$
    – kglr
    Jul 28 '18 at 15:33
1
$\begingroup$

You can use the option ImageMargins.

Using an example with smaller numbers:

size = {550, 320}; is = 200;
Plot[{x, Sqrt[x]}, {x, 0, 2}, ImageSize -> is, AspectRatio -> 1, 
 ImageMargins -> {{#, #} &@(size[[1]] - is) / 2, {#, #} &@(size[[2]] - is)/2}]

enter image description here

Use size = {1340, 600}; is = 500; to get your desired result.

$\endgroup$
2
  • $\begingroup$ Many thanks, just what I wanted! I cannot seem to find information what unit length is used when I set the ImageSize. Is it mm or pixels or...? $\endgroup$
    – mf67
    Jul 28 '18 at 16:13
  • $\begingroup$ @mf67, ImageSize >> Details says it is in printer points. $\endgroup$
    – kglr
    Aug 29 '18 at 0:10

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.