# Centre figure by plot region [closed]

I want to export a plot with axes as a graphic where the plot is centred within a white/transparent background region such that the centre of the plot region coincides with the centre of the background. By default, if one exports a plot, then centres the graphic within another program (Word/LaTeX etc) the plot region is not centred but the overall image.

plot = Plot[x^2, {x, 0, 5}, Frame -> True, FrameLabel -> {x, x^2}]
Export["plot.pdf", plot]; As can be seen above, the plot region (the black rectangle) is not centred within the image (the orange box).

• Use ImagePadding, f.e. plot = Plot[x^2, {x, 0, 5}, Frame -> True, FrameLabel -> {x, x^2}, ImagePadding -> 50] – C. E. Aug 8 '16 at 14:38
• Ahh of course, so simple. Thank you. – Tom Aug 8 '16 at 14:40

The straightforward way is to add equal ImagePadding to all sides of the plot what is as easy as adding ImagePadding -> 40:

plot = Plot[x^2, {x, 0, 5}, Frame -> True, FrameLabel -> {x, x^2}, Here is how exported PDF file looks when opened by Adobe Acrobat:

Export["plot.pdf", plot]; If I wanted the bounding box to be the smallest size while keeping the frame in the center, I would add phantom elements to the right and top borders.

Plot[x^2, {x, 0, 5}, Frame -> True, FrameTicks -> All,
FrameTicksStyle -> {{Directive[Black],
Directive[Opacity]}, {Directive[Black],
Directive[Opacity]}},
FrameLabel -> {{x, Style[x, White]}, {x^2, Style[x^2, White]}}]


See m_goldberg's comment below for better code.

• This is good idea, but the execution could be improved. You have the frame label order wrong and the frame tick style could be written more concisely. Consider editing your code like so: Plot[x^2, {x, 0, 5}, Frame -> True, FrameTicks -> All, FrameTicksStyle -> {{Black, Transparent}, {Black, Transparent}}, FrameLabel -> {{x^2, Style[x^2, White]}, {x, Style[x, White]}}] – m_goldberg Aug 8 '16 at 17:49