1

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?

Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78

2 Answers2

5

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

george2079
  • 38,913
  • 1
  • 43
  • 110
3

OP confirmed that PlotRangePadding is what solves the problem.

Plot[x^2 - 5 x - 10, {x, 0, 8},   PlotRangePadding -> {Automatic, {Automatic, 8}}]
Kuba
  • 136,707
  • 13
  • 279
  • 740