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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46725] RE: [mg46717] RE: [mg46703] How to combine two functions in one plot using a left and a right y-axis
  • From: "David Park" <djmp at earthlink.net>
  • Date: Wed, 3 Mar 2004 02:30:35 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Thank you Hartmut.

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

Needs["DrawGraphics`DrawingMaster`"]

Draw2D[
    {Draw[Cos[30/(1 + x^2)], {x, -10, 10}],
     Red, 
     Draw[30/(1 + x^2), {x, -10, 10}] /. 
        DrawingTransform[#1 &, -0.6 + #2/15 &]},
    Frame -> True,
    FrameTicks ->
      {Automatic,
        CustomTicks[Identity, {-1, 1, 1, 5}],
        Automatic,
        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 earthlink.net
http://home.earthlink.net/~djmp/ 





From: Wolf, Hartmut [mailto:Hartmut.Wolf at t-systems.com]
To: mathgroup at smc.vnet.net

>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: [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?
>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: 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