Skip to main content
fixed the function so that it doesn't rescale the abscissa
Source Link
Rico Picone
  • 895
  • 1
  • 5
  • 12

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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 -> {Automatic#[[2]], (1.2*{-#[[2]]#[[3]], #[[2]]#[[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).

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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 //
    { #, Max@Abs@Last[PlotRange /. AbsoluteOptions[#, PlotRange]] } & //
      Show[ #[[1]], PlotRange -> {Automatic, (1.2*{-#[[2]], #[[2]]})} ] & 

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).

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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).

fixed PlotRange in function
Source Link
Rico Picone
  • 895
  • 1
  • 5
  • 12

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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 //
    { #, Max@Abs@Last[PlotRange /. AbsoluteOptions[#, PlotRange]] } & //
      Show[ #[[1]], PlotRange -> {Automatic, (1.2*{-#[[2]], #[[2]]})} ] & 

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).

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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 //
    { #, Max@Abs@Last[PlotRange /. AbsoluteOptions[#, PlotRange]] } & //
      Show[ #[[1]], PlotRange -> (1.2*{-#[[2]], #[[2]]}) ] & 

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).

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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 //
    { #, Max@Abs@Last[PlotRange /. AbsoluteOptions[#, PlotRange]] } & //
      Show[ #[[1]], PlotRange -> {Automatic, (1.2*{-#[[2]], #[[2]]})} ] & 

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).

added 151 characters in body
Source Link
Rico Picone
  • 895
  • 1
  • 5
  • 12

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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 //
    { #, Max@Abs@Last[PlotRange /. AbsoluteOptions[#, PlotRange]] } & //
      Show[ #[[1]], PlotRange -> (1.2*{-#[[2]], #[[2]]}) ] & 

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).

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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 //
    { #, Max@Abs@Last[PlotRange /. AbsoluteOptions[#, PlotRange]] } & //
      Show[ #[[1]], PlotRange -> (1.2*{-#[[2]], #[[2]]}) ] & 

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 } 
 ]

asymmetric plots

But we might want the PlotRange to go from $+1$ to $-1$ instead, like:

symmetric plot

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 //
    { #, Max@Abs@Last[PlotRange /. AbsoluteOptions[#, PlotRange]] } & //
      Show[ #[[1]], PlotRange -> (1.2*{-#[[2]], #[[2]]}) ] & 

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).

Tweeted twitter.com/#!/StackMma/status/483751336702644224
added function
Source Link
Rico Picone
  • 895
  • 1
  • 5
  • 12
Loading
Source Link
Rico Picone
  • 895
  • 1
  • 5
  • 12
Loading