MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: reversing the direction of the X axis in Plot and ListPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93124] Re: reversing the direction of the X axis in Plot and ListPlot
  • From: Januk <ggroup at sarj.ca>
  • Date: Mon, 27 Oct 2008 03:13:49 -0500 (EST)
  • References: <gdrq87$mmd$1@smc.vnet.net>

Hi Michael,

You could use a ParametricPlot to do the reversal for you.  It would
then simply be a matter of reversing the tick mark labels.  You might
start with something like the following:

SetAttributes[PlotReverse, HoldAll]
PlotReverse[func_, {t_, tmin_, tmax_}, opts___] :=
 Module[{pl1, ticks, t1},
  pl1 = ParametricPlot[
    Evaluate[{tmax - t1, func /. t -> t1}],
    {t1, tmin, tmax},
    opts];
  ticks = Ticks /. AbsoluteOptions[pl1];
  ticks[[1, All, 2]] =
   ticks[[1, All, 2]] /. {x_?NumericQ :> tmax - x};

  Show[pl1, Ticks -> ticks]
  ]


f[x_] := Exp[x/40]
PlotReverse[f[x], {x, 0, 180}, AspectRatio -> 1/GoldenRatio]
Plot[f[x], {x, 0, 180}, AspectRatio -> 1/GoldenRatio]

I hope that helps,
Januk

On Oct 24, 2:33 am, Stern <nycst... at gmail.com> wrote:
> I'm graphing some bond values where the natural flow is for the x axis,
> which represents days to maturity, to run from from big numbers to small
> ones. I can achieve this by expressing my function in terms of days past
> (which run small to big) and then using Ticks to label the axis the other
> direction (as though it were days to maturity), but this feels like a
> complex solution to a simple problem. Is there an easy way to Plot a
> function from 180 to 0, rather than 0 to 180?
>
> Thanks,
>
> Michael



  • Prev by Date: Solving systems of eqs involving Integrations over product of
  • Next by Date: Re: PrintTemporary
  • Previous by thread: reversing the direction of the X axis in Plot and ListPlot
  • Next by thread: Graphic Entries in a Grid