MathGroup Archive 1999

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

Search the Archive

Re: second y-axis in a graph

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20540] Re: [mg20515] second y-axis in a graph
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 30 Oct 1999 00:13:56 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Anton wrote:

>I would like to plot two functions with "DisplayTogether" in
>one graphics. However, I would need a second y-axes since
>the numbers of the second function are much smaller than
>those of the first function.
>Is there any way to add a second y-axis and relate a
>function to that axis?
>A.Krumm
>


Here is one example of doing what you wish.

<< Graphics`Colors`

f[x_] := Exp[x];
g[x_] := Sin[x];

We are going to plot these two functions in a Frame, and put tick marks and labels on
the right hand side as a "second y axis".  We scale the Exp function so the maximum
value is 1. We use red and black to match the functions and axis labels. The
following defines the tick marks for the right hand side. (Look up FrameTicks and
Ticks in Help.)

fticks = Transpose[{Range[0, 1, 0.25], f[2]Range[0, 1, 0.25]}] /. {a_,
          b_} :> {a, StyleForm[NumberForm[b, {3, 2}], FontColor -> Red]};

We can now make the two plots and display them together in a Show statement.

Block[{$DisplayFunction = Identity},
    p1 = Plot[Evaluate[f[x]/f[2]], {x, 0, 2}, PlotStyle -> Red];
    p2 = Plot[g[x], {x, 0, 2}]];

Show[p1, p2, Frame -> True,
    FrameTicks -> {Automatic, Automatic, None, fticks},
    PlotLabel ->
      SequenceForm[StyleForm[f[x], FontColor -> Red], " and ", g[x]]];

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



  • Prev by Date: Re: Partitioning lists
  • Next by Date: Electromagnetics notebooks
  • Previous by thread: Re: second y-axis in a graph
  • Next by thread: Re: Levy Distributions/Time Series