Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Re: Reverse Axes in Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23714] Re: [mg23697] Re: [mg23659] Reverse Axes in Plot
  • From: BobHanlon at aol.com
  • Date: Mon, 29 May 2000 22:05:45 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 5/29/2000 1:04:21 PM, BobHanlon at aol.com writes:

>In a message dated 5/28/2000 11:25:24 PM, chapmand at accesscable.net writes:
>
>>I would like to plot a simple 2D plot with the y-axis increasing
>>DOWNwards instead of UPwards.  Does anyone know how to do this?  I have
>>looked high and low for the answer!
>>
>
>Using Version 4,
>
>reversedPlot[expr_, 
>    {var_Symbol, varMin_?NumericQ, varMax_?NumericQ}, 
>    {REVx_?(Element[#, Booleans] &), 
>      REVy_?(Element[#, Booleans] &)}, 
>    opts___] := 
>  Module[{plt = 
>        Plot[expr, {var, varMin, varMax}, opts, DisplayFunction -> 
Identity]},
>     Show[{
>        plt /. 
>          {x_?NumericQ, y_?NumericQ} :> {If[REVx, -x, x], If[REVy, -y,
>y]}}, 
>      Ticks ->  {
>          If[REVx, (Ticks  /. AbsoluteOptions[plt, Ticks])[[1]] /. 
>              {x_, label_, len_, style_} :> {-x, label, len, style}, 
>            Automatic], 
>          If[REVy, (Ticks  /. AbsoluteOptions[plt, Ticks])[[2]] /. 
>              {y_, label_, len_, style_} :> {-y, label, len, style}, 
>            Automatic]
>          }, 
>      DisplayFunction -> $DisplayFunction]]
>
>f[x_] := 3x - 7
>
>xmin = -2; xmax = 5;
>
>Basic Plot
>
>Plot[f[x], {x, xmin, xmax}, PlotStyle -> RGBColor[1, 0, 0]];
>
>reversedPlot with neither axis reversed, i.e., same as basic Plot
>
>reversedPlot[f[x], {x, xmin, xmax}, {False, False}, 
>    PlotStyle -> RGBColor[1, 0, 0]];
>
>reversedPlot with y axis reversed
>
>reversedPlot[f[x], {x, xmin, xmax}, {False, True}, 
>    PlotStyle -> RGBColor[1, 0, 0]];
>
>reversedPlot with x axis reversed
>
>reversedPlot[f[x], {x, xmin, xmax}, {True, False}, 
>    PlotStyle -> RGBColor[1, 0, 0]];
>
>reversedPlot with both x and y axes reversed
>
>reversedPlot[f[x], {x, xmin, xmax}, {True, True}, 
>    PlotStyle -> RGBColor[1, 0, 0]];
>

As some more experimentation, I noted some required corrections:

reversedPlot[expr_, 
    {var_Symbol, varMin_?NumericQ, 
      varMax_?NumericQ}, {REVx_?(Element[#, Booleans] &), 
      REVy_?(Element[#, Booleans] &)}, opts___] := 
  Module[
    {plt  = 
        Plot[expr, {var, varMin, varMax}, opts, DisplayFunction -> Identity], 
      xTicks, yTicks}, 
    xTicks = (Ticks  /. AbsoluteOptions[plt, Ticks])[[1]] ;
    yTicks = (Ticks  /. AbsoluteOptions[plt, Ticks])[[2]];
    Show[plt /.  
        Line[pts_] :> 
          Line[{If[REVx, -1, 1]*#[[1]], If[REVy, -1, 1]*#[[2]]} & /@ pts], 
      Ticks ->  {
          If[REVx, 
            xTicks /.  {x_, label_, len_, style_} :> {-x, label, len, style}, 
            xTicks], 
          If[REVy, 
            yTicks /. {y_, label_, len_, style_} :> {-y, label, len, style}, 
            yTicks]
          }, 
      DisplayFunction -> (DisplayFunction /. {opts} /. 
            DisplayFunction -> $DisplayFunction)]]

This revision to reversedPlot enables (1) specification of Tick marks on an 
axis which is not reversed to be carried forward (i.e., uses specified ticks 
rather than Automatic), (2) optional suppression of the display of the 
reversedPlot (i.e., use of DisplayFunction -> Identity), and (3) 
specification of PlotRange.

Show[GraphicsArray[Outer[
        reversedPlot[{3x*Sin[3x/2], x}, {x, -Pi, 2Pi}, {#2, #1}, 
            PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 0, 1]},  
            Ticks -> {Join[
                  Table[{x, ToString[x], {.015, .015}}, {x, -Pi, 2Pi, Pi}], 
                  Table[{x, "", {.004, 0.}}, {x, -Pi, 2Pi, Pi/8}]], 
                Automatic}, 
            PlotRange -> {-16, 16}, DisplayFunction -> Identity] &, 
        {False, True}, {False, True}]], ImageSize -> {500, 310}];

Note that Boolean argument to reversedPlot is reversed to {#2, #1} to align 
axes in GraphicsArray.


Bob

BobHanlon at aol.com


  • Prev by Date: Re: Newbie Q: Referencing Auto-number Cells
  • Previous by thread: Re: Reverse Axes in Plot
  • Next by thread: About MathReader 3.0 - with a certain Urgency!!!