9
$\begingroup$

I have plot generated by Plot[] function that I want to export to pdf file. The problem is that Export[] function somehow cuts a tiny bit of plot on the left side which results in something like this: Exported image

I'd like to know what should I do to get exported file without cropped $0$.

$\endgroup$
2
  • 3
    $\begingroup$ It's always best if you provide an example of the code you used. But even without that, I would suggest manually setting the Plot option ImagePadding -> 70 (or use a larger number). $\endgroup$
    – Jens
    Jun 22, 2012 at 17:20
  • $\begingroup$ @Jens thanks, that works good. $\endgroup$
    – qoqosz
    Jun 22, 2012 at 17:25

2 Answers 2

5
$\begingroup$

Here is my original suggestion using ImagePadding:

p = Plot[Cos[x], {x, 0, 2}, AxesStyle -> Arrowheads[.1], 
  PlotRange -> {0, 1}, TicksStyle -> Large, RotateLabel -> False, 
  ImagePadding -> 70]

imagemargins

And here is an example of how to use ImageMargins in the plot command:

p = Plot[Cos[x], {x, 0, 2}, AxesStyle -> Arrowheads[.1], 
  PlotRange -> {0, 1}, TicksStyle -> Large, RotateLabel -> False, 
  ImageMargins -> 70]

Both methods work to give you extra space around the image. But I see Mr. Wizard just now explained this already.

Edit: a note for completeness

In a related question, one can see that neither ImagePadding nor ImageMargins work in some situations. Here is an example where Epilog is used to place a text below a plot:

Plot[Sin[x], {x, 0, 2 Pi}, 
 Epilog -> {Text["Show me the text", {Pi, -1.3}]}]

The text is not shown because it falls outside the PlotRange. When this happens, you can fix the problem by using PlotRangePadding:

Plot[Sin[x], {x, 0, 2 Pi}, 
 Epilog -> {Text["Show me the text", {Pi, -1.3}]}, 
 PlotRangePadding -> .5]

plot with epilog

$\endgroup$
4
  • $\begingroup$ I reduced my answer to this after realizing I was confusing ImagePadding and ImageMargins. $\endgroup$
    – Mr.Wizard
    Jun 22, 2012 at 17:32
  • $\begingroup$ @Mr.Wizard Now you confuse me because I was editing while you were too... Hopefully all the bases are covered now. $\endgroup$
    – Jens
    Jun 22, 2012 at 17:34
  • $\begingroup$ Jens, sorry, if I had been thinking clearly about ImageMargins/ImagPadding from the start I would have not have had to make a series of edits. $\endgroup$
    – Mr.Wizard
    Jun 22, 2012 at 17:39
  • $\begingroup$ That's OK - you got my +1. $\endgroup$
    – Jens
    Jun 22, 2012 at 17:40
10
$\begingroup$

Please try adding some space around the plot:

Plot[2 Sin[x] + x, {x, 0, 15}, Filling -> Bottom, ImageMargins -> 10]

ImageMargins gives a margin around the existing plot that can be seen by selecting the graphic (the outer orange frame):

enter image description here

By comparison ImagePadding is used by Plot itself to make room for the axes labels (the inner orange frame).

$\endgroup$
3
  • $\begingroup$ Thanks, but proposed ImagePadding option works good and is sufficient for my needs. $\endgroup$
    – qoqosz
    Jun 22, 2012 at 17:27
  • $\begingroup$ @qoqosz actually I didn't see that comment above, and also I was confusing ImageMargins with ImagePadding; you can use ImageMargins directly in Plot and that would be a good method because you can use a small fixed value without cutting of the labels, as you would with ImagePadding. $\endgroup$
    – Mr.Wizard
    Jun 22, 2012 at 17:30
  • $\begingroup$ Ok, good to know :) $\endgroup$
    – qoqosz
    Jun 22, 2012 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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