MathGroup Archive 2004

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

Search the Archive

RE: How to combine two functions in one plot using a left and a right y-axis

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46717] RE: [mg46703] How to combine two functions in one plot using a left and a right y-axis
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Tue, 2 Mar 2004 19:10:16 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Ronald Cornelussen [mailto:ronaldc at science.uva.nl]
To: mathgroup at smc.vnet.net
>Sent: Tuesday, March 02, 2004 6:14 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg46717] [mg46703] How to combine two functions in one plot 
>using a left
>and a right y-axis
>
>
>Hi all,
>Can someone help me with the following problem. I want to combine two 
>functions with different scales in one plot, using a left and a right 
>y-axis. Is there a way to do this?
>Thanks,
>Ronald
>

The basic idea is to scale (at least one of the graphs) + the corresponding
ticks.
For example:
 
In[1]:=
g1 = Plot[Cos[30/(1 + x^2)], {x, -10, 10}, Frame -> True]

In[2]:=
g2 = Plot[30/(1 + x^2), {x, -10, 10}, Frame -> True, PlotStyle -> Hue[0], 
    Axes -> False, FrameTicks -> {Automatic, None, None, True}]
 

We scale g2:

In[3]:= scale[y_] := -.6 + y/15

In[4]:= scaledTicks = 
    FullOptions[g2, FrameTicks][[4]] /. {y_Real, label_, len_, 
          style_} :> {scale[y], label, len, style};

In[5]:= scaledGraph = Graphics[g2[[1]]] /. {x_Real, y_Real} :> {x,
scale[y]};


...and combine

In[6]:=
Show[g1, scaledGraph, 
  FrameTicks -> {Automatic, FullOptions[g1, FrameTicks][[2]], None, 
      scaledTicks}]



But I'm sure, David Park has something better to offer at
http://home.earthlink.net/~djmp/Mathematica.html


--
Hartmut Wolf


  • Prev by Date: Re: Printing digits of Pi
  • Next by Date: Re: Elliptic Integral problem with 5.0
  • Previous by thread: Re: How to combine two functions in one plot using a left and a right y-axis
  • Next by thread: RE: RE: How to combine two functions in one plot using a left and a right y-axis