MathGroup Archive 2004

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

Search the Archive

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

Thank you Hartmut.

So here is how I would do it with DrawGraphics...


    {Draw[Cos[30/(1 + x^2)], {x, -10, 10}],
     Draw[30/(1 + x^2), {x, -10, 10}] /. 
        DrawingTransform[#1 &, -0.6 + #2/15 &]},
    Frame -> True,
    FrameTicks ->
        CustomTicks[Identity, {-1, 1, 1, 5}],
        CustomTicks[-0.6 + #1/15 &, {0, 30, 10, 5},
          CTNumberFunction -> (StyleForm[#, FontColor -> Red] &)]},
    Background -> Linen,
    PlotLabel -> "Two Scale Plot",
    ImageSize -> 450];

David Park
djmp at 

From: Wolf, Hartmut [mailto:Hartmut.Wolf at]
To: mathgroup at

>From: Ronald Cornelussen [mailto:ronaldc at]
To: mathgroup at
>Sent: Tuesday, March 02, 2004 6:14 AM
>To: mathgroup at
>Subject: [mg46725] [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?

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

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,

...and combine

Show[g1, scaledGraph, 
  FrameTicks -> {Automatic, FullOptions[g1, FrameTicks][[2]], None, 

But I'm sure, David Park has something better to offer at

Hartmut Wolf

  • Prev by Date: Re: To create {{},{},....{}} beyond $MaxRecursionLimit
  • Next by Date: Euler rotation angles
  • Previous by thread: RE: How to combine two functions in one plot using a left and a right y-axis
  • Next by thread: Re: Functions Mapping