Say one had a function that was itself asymmetric about the abscissa, but one desired to plot it on a symmetric ordinate. How can this be achieved with Plot
automatically (without separately computing the limits and providing them to Plot
)?
Example
The plot of 1/2
serves as a sufficient example.
Table[
Plot[
1/2,
{ x, 0, 1 },
Frame -> { False, True }[[i]],
Axes -> { True, False }[[i]]
],
{ i, 1, 2 }
]
But we might want the PlotRange
to go from $+1$ to $-1$ instead, like:
I did this with the option PlotRange
, but short of finding the maximum of the absolute value of the function and setting PlotRange
, I don't know how to automate this.
Specifically, is it possible to use Plot
in a native manner to do this?
Solution (based on the answer by Szabolcs) Here's a little function that implements the answer.
plotSym[ plot_ ] :=
plot //
{
#,
First[PlotRange /. AbsoluteOptions[#, PlotRange]],
Max@Abs@Last[PlotRange /. AbsoluteOptions[#, PlotRange]]
} & //
Show[ #[[1]], PlotRange -> {#[[2]], (1.2*{-#[[3]], #[[3]]})} ] &
Note: I added the factor of 1.2
as a way to give the plot a little more room. It can be anything nonzero (including the likely more-desirable 1
).