9
$\begingroup$

You can see that there are gaps on all sides of the plot between the frame and the extent of the line that I've plotted. How do I get rid of these? I'd like the frame to cover $[0,1]\times[0,1]$ and no more.

Plot[x, {x, 0, 1}, Frame -> True]

enter image description here

$\endgroup$
3
  • $\begingroup$ One way is to specify PlotRange as in Plot[x, {x, 0, 1}, Frame -> True, PlotRange -> {{0, 1}, {0, 1}}]. $\endgroup$ Commented Jan 31, 2013 at 12:57
  • $\begingroup$ @b.gatessucks This also works; thanks! $\endgroup$ Commented Jan 31, 2013 at 13:22
  • $\begingroup$ Related: (3618), (7453), (9346) $\endgroup$
    – Mr.Wizard
    Commented Mar 7, 2017 at 6:23

1 Answer 1

13
$\begingroup$
Plot[x, {x, 0, 1}, Frame -> True, PlotRangePadding -> 0]

Mathematica graphics

The key to the solution was PlotRangePadding -> 0.

$\endgroup$
5
  • $\begingroup$ Whoops, I missed that. I was looking for options relating to Frame. Thanks! $\endgroup$ Commented Jan 31, 2013 at 13:21
  • 1
    $\begingroup$ @Will I understand; there are a lot of options, especially for plotting and graphics. $\endgroup$
    – Mr.Wizard
    Commented Jan 31, 2013 at 13:29
  • $\begingroup$ PlotRangePadding->0 did not quite eliminate the white space in my ContourPlot and StreamPlot, but PlotRangePadding->-0.02 did. $\endgroup$ Commented Apr 18, 2017 at 0:39
  • $\begingroup$ @Sander That's a bit unexpected in the case of ContourPlot; which version are you using, and is it with every plot or specific code? StreamPlot does seem to leave some extra space so a negative padding value makes more sense there. $\endgroup$
    – Mr.Wizard
    Commented Apr 18, 2017 at 6:20
  • $\begingroup$ @Mr.Wizard You are right, the ContourPlot on its own does not leave white space with 0 padding. The white space on it was due to overlaying with the previous StreamPlot using Show[]. I guess it inherited the StreamPlot's padding. $\endgroup$ Commented Apr 20, 2017 at 1:52

Your Answer

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

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