# Manipulation of Automatic settings in a given case

Often I use the Automatic option to specify plot styles, plot ranges, image sizes, etc. I'd like to be able to apply some modifications to these automatically defined values. For example, if a plot with the PlotRange -> Automatic would draw the function on the interval $[0,1]$, I'd like to be able to use something like PlotRange -> #*2 & /@ Automatic to extend the plot range to $[0,2]$. Is this possible in general, or maybe every case would need a specific solution?

I'm not sure what tags are most appropriate for this topic, please add them if you think they're more suitable than the one I've chosen.

-
Does something like PlotRangePadding -> Scaled[0.25] do what you're after? –  Michael E2 Jun 22 '13 at 19:08
It works in this particular case, but not with Automatic in general. Automatic can be a single number, a list or array of numbers, a color rule, some other styling directive, a method used in computation of a function... –  shrx Jun 22 '13 at 19:26
It makes sense with something like PlotRange, but I can't imagine what Method -> 2*Automatic or f@Automatic would mean, that wouldn't be clearer with an explicit setting. –  Michael E2 Jun 22 '13 at 20:07

My dirty, as usual, post-processing solution

Row@{
Plot[Sin@x, {x, 0, Pi}, PlotRange -> Automatic, ImageSize -> 300],
Plot[Sin@x, {x, 0, Pi}, PlotRange -> Automatic, ImageSize -> 300] /.
x : Rule[PlotRange, __] :> Rule[PlotRange, ({#1, 2 #2} & @@ x[[2]])]}


One could simplify replacement rule, then it could be started to be considered some kind of solution.

-
Yes, this is something I'm looking for. I'm going to play with it a bit. –  shrx Jun 22 '13 at 20:28
@shrx Please report if You manage to shorten replacement rule. I'm glad You like it. –  Kuba Jun 22 '13 at 20:33
This will not work in all cases. AbsoluteOptions is more reliable (though far from foolproof, it has plenty of inconsistencies) –  Szabolcs Jun 23 '13 at 9:46
I should have of course given an example when it does not work: Graphics[Circle[], PlotRange -> Automatic] –  Szabolcs Jun 23 '13 at 9:49
@Szabolcs Of course I agree. I should have put some more effort to describe limitations of this method. –  Kuba Jun 23 '13 at 10:17

This is a rather common annoyance. In the case of most functions, there is no general way to find out what an Automatic setting does---you'd have to check the docs for it.

In the case of Graphics object however (what most plotting functions produce), you can typically use AbsoluteOptions to retrieve the actual numerical value of the setting.

For example, let's take

g = Graphics[Circle[], PlotRange -> Automatic] (* the default option value is PlotRange -> All *)


Now Options[g, PlotRange] just return Automatic. AbsoluteOptions[g, PlotRange] returns PlotRange -> {{-1., 1.}, {-1., 1.}}.

Once you have the value of the option, you can use Show to create a version of the graphics object with a modified value:

pr = PlotRange /. AbsoluteOptions[g, PlotRange]
Show[g, PlotRange -> 2 pr]


Unfortunately AbsoluteOptions is not entirely reliable, especially with options controlling padding and margins. See for example here. It is the first thing you should try though.

Also take a look at FullGraphics with the caveat that its output is typically just an approximation, and may not correspond to the input completely. It still has good uses though.

-
It's strange that AbsoluteOptions work for Plot but not for PolarPlot. –  shrx Jun 23 '13 at 10:45
@shrx I'd call that a PolarPlot bug. I think the form PlotRange -> {{Automatic, Automatic}, {Automatic, Automatic}} is incorrect. You could report this. You can work around it by using Show to correct the option value on the PolatPlot output. –  Szabolcs Jun 23 '13 at 11:06