1
$\begingroup$

if I have a plot let us say

Plot[x^2 - 5 x - 10, {x, 0, 8}]

I want o check if there is a way to know the automatic plot range and to add or subtract from that range as I need.

I will assume something fictitious like this:

Plot[x^2 - 5 x - 10, {x, 0, 8}, PlotRange -> (Automatic + {0, 10})]

is there a way to do something like this?

$\endgroup$
7
  • 1
    $\begingroup$ Are you asking about y axis? Plot[x^2 - 5 x - 10, {x, 0, 8}, PlotRangePadding -> {Automatic, {Automatic, 8}}] ? $\endgroup$
    – Kuba
    Commented May 25, 2014 at 15:20
  • 1
    $\begingroup$ Related: "How to get the real PlotRange?" $\endgroup$ Commented May 25, 2014 at 15:31
  • $\begingroup$ @Kuba yes I am asking about y axis. thanks for the answer. can that be applied for both sides of y axis (+y and -y)? $\endgroup$ Commented May 25, 2014 at 15:37
  • $\begingroup$ @Algohi It's unclear what it is about. PlotRange padding will not create parts of plot that are not already there. Take as example Tan[x]. About x axis, isn't it the second argument of Plot? $\endgroup$
    – Kuba
    Commented May 25, 2014 at 16:08
  • $\begingroup$ pretty sure in general you need to generate the plot use AbsoluteOptions[] or some such to get the range then re-plot. $\endgroup$
    – george2079
    Commented May 25, 2014 at 17:32

2 Answers 2

3
$\begingroup$

OP confirmed that PlotRangePadding is what solves the problem.

Plot[x^2 - 5 x - 10, {x, 0, 8},   PlotRangePadding -> {Automatic, {Automatic, 8}}]
$\endgroup$
5
$\begingroup$

just for completeness here is the issue with padding, if automatic ranging clipped the function, PlotRangePadding does not recover the clipped portion:

 Plot[ 1/x , {x, -1, 1},
     PlotRangePadding -> {Automatic, {10, 10}}]

enter image description here

Fix by generating the plot first to get the auto generated range then again with manual padding:

 Plot[1/x, {x, -1, 1}, 
     PlotRange -> ({#[[1]], #[[2]] + {-10, 10}} &@
      (PlotRange /.  AbsoluteOptions[Plot[ 1/x , {x, -1, 1}]]))]

enter image description here

$\endgroup$
1
  • $\begingroup$ you are right about this. I will consider this way also. great thanks. $\endgroup$ Commented May 27, 2014 at 17:10

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.