MathGroup Archive 2001

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

Search the Archive

Re: Two Y-Axes

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27313] Re: Two Y-Axes
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 20 Feb 2001 03:05:22 -0500 (EST)
  • References: <96q2lp$mtv@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bob,


A scaling function, rather than a factor, will genralize the method:

plotTwo[{leftAxisPlot_, rightAxisPlot_}, iter_, opts___] :=
    Module[{pltL, pltR, ytckL, ytckR, maxL, minL, maxR, minR, scale},
      pltL = Plot[leftAxisPlot, iter, opts, DisplayFunction -> Identity];
      pltR = Plot[rightAxisPlot, iter, opts, DisplayFunction -> Identity];
      ytckL = (Ticks /. AbsoluteOptions[pltL])[[2]];
      ytckR = (Ticks /. AbsoluteOptions[pltR])[[2]];
      maxL = Max[ytckL][[1]];
      minL = Min[ytckL][[1]];
      maxR = Max[ytckR][[1]];
      minR = Min[ytckR][[1]];

      scale = minL + ((maxL - minL)*(-minR + #1))/(maxR - minR) &;

      Plot[{leftAxisPlot, scale[rightAxisPlot]}, iter,
        Evaluate[
          Flatten[{Frame -> True, Axes -> False,
              FrameTicks -> {Automatic, Automatic, Automatic,
                  ytckR /. {(x__)?NumericQ, z__} :> {scale[x], z}}, opts}]]]
    ];

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

<BobHanlon at aol.com> wrote in message news:96q2lp$mtv at smc.vnet.net...
> This will handle simple examples
>
> plotTwo[{leftAxisPlot_, rightAxisPlot_}, iter_, opts___] :=
>     Module[{pltL, pltR, ytckL, ytckR, maxL, maxR, minR, scale},
>       pltL = Plot[leftAxisPlot, iter, opts, DisplayFunction ->  Identity];
>       pltR = Plot[rightAxisPlot, iter, opts, DisplayFunction -> Identity];
>       ytckL = (Ticks /. AbsoluteOptions[pltL])[[2]];
>       ytckR = (Ticks /. AbsoluteOptions[pltR])[[2]];
>       maxL = Max[ytckL][[1]];
>       maxR = Max[ytckR][[1]];
>       minR = Min[ytckR][[1]];
>       scale=
>         If[maxR+minR == 0, maxL/maxR, (maxL+Min[ytckL][[1]])/(maxR+minR)];
>       Plot[{leftAxisPlot, scale*rightAxisPlot}, iter,
>         Evaluate[
>           Flatten[{Frame -> True, Axes -> False,
>               FrameTicks -> {Automatic, Automatic, Automatic,
>                   ytckR /. {(x__)?NumericQ, z__} :> {scale*x, z}},
>               opts}]]]];
>
> red = RGBColor[1, 0, 0];  blue = RGBColor[0, 0, 1];
>
> Needs["Statistics`ContinuousDistributions`"];
>
> dist = NormalDistribution[mu = 1+Random[], sigma = 2*Random[]];
>
> plotTwo[{PDF[dist,x], CDF[dist,x]}, {x, mu-3*sigma, mu+3*sigma},
>     PlotStyle -> {blue, red},
>     FrameLabel -> {
>         StyleForm["\nx", FontWeight -> "Bold", FontSize -> 12],
>         StyleForm["PDF\n", FontWeight -> "Bold", FontSize -> 12,
>           FontColor -> blue],
>         StyleForm["Normal Distribution\n", FontWeight -> "Bold",
>           FontSize -> 14],
>         StyleForm["\nCDF", FontWeight -> "Bold", FontSize -> 12,
>           FontColor -> red]},
>     ImageSize -> {500, 350}];
>
> plotTwo[{x,E^x}, {x,0,10}, PlotRange -> All, PlotStyle -> {blue,red},
>     FrameLabel -> {
>         StyleForm["\nx", FontWeight -> "Bold", FontSize -> 12],
>         StyleForm["Linear (x)\n", FontWeight -> "Bold", FontSize -> 12,
>           FontColor -> blue],
>         None,
>         StyleForm["\nExponential (e^x)", FontWeight -> "Bold",
>           FontSize -> 12, FontColor -> red]},
>     ImageSize -> {500, 325}];
>
> Bob Hanlon
>
> In a message dated 2001/2/18 5:00:22 AM, hmeier at webshuttle.ch writes:
>
> >Your code for two (differently scaled) y-axes is a - very - valuable
addendum
> >to the plotting capabilities of Mathematica.
> >
> >However, for everyday use it may be preferable to automate ticks and tick
> >labels (to give appropriate plot ranges in all cases and to ensure "nice
> >round numbers", among other things).
> >
> >I think of the following steps:
> >
> >1a) compute plot 1, without rendering it
> >1b) extract ticks 1 with AbsoluteOptions[g1,Ticks]
> >2a) compute (scaled) plot 2, without rendering it
> >2b) extract ticks 2 with AbsoluteOptions[g2,Ticks]
> >3)   render the combined plot, where ticks 1 and 2 are given as values
> >      to Option FrameTicks.
> >
> >The package Ticks.m in ExtendGraphics Packages (Math Source item
0205-041)
> >may perhaps also be used to "plug in automatically" tick marks and tick
> >labels for the (scaled) second plot.
> >
> >I was not able to develop a working program along one of those ideas.
> >
> >The User Group would be certainly interested in a program for differently
> >scaled y-axes that would be more automated and therefore easier to use.
> >Many people would appreciate if you had some time to spend ....
> >
>






  • Prev by Date: Re: RE: inverting y axis in DensityPlot
  • Next by Date: rendering with Polygon vs. Cuboid
  • Previous by thread: Re: 2D Outlines to 3D Surface or Solid
  • Next by thread: rendering with Polygon vs. Cuboid