MathGroup Archive 2011

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

Search the Archive

Re: y-axis direction


"Rob Y. H. Chai" wrote:

> Hi all,
>
> In the Plot command, the convention for y-axis is up for positive values. Is
> there an easy way to reverse the y-axis direction i.e. pointing down for
> increasing positive y values? Thanks.
>
> Rob Chai

You can plot -f[x] and then adjust the labels on the y-axis. Try this:

Options[plotyDown] = Options[Plot];
plotyDown[f_, {x_, von_, bis_}, opts:OptionsPattern[]] :=
Module[{yTicks, vz, pp},
  vz[{n_, l_?NumericQ, rest__}] := {n, -l, rest};
  vz[{n_, rest__}] := {n, rest};
  pp = Plot[-f, {x, von, bis}, opts];
  yTicks = vz /@ (AbsoluteOptions[pp, Ticks][[1, 2, 2]]);
  Plot[-f, {x, von, bis}, Ticks -> {Automatic, yTicks}, opts]
]

Example:

f[x_] := x^2/Sin[x]
GraphicsRow[{
  Plot[f[x], {x, -\[Pi], 2 \[Pi]}, PlotRange -> {-50, 60}],
  plotyDown[f[x], {x, -\[Pi], 2 \[Pi]}, PlotRange -> {-50, 60}]}]
  
-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: ContourPlot3D
  • Next by Date: Re: y-axis direction
  • Previous by thread: y-axis direction
  • Next by thread: Re: y-axis direction