[?] Plot given ranges on two axis?

Hi Anil,

Here an example of a TwoAxisPlot with a simple relation between two functions

Plot[{Sin[x], 3 Sin[x] + 5 Cos[x]}, {x, 0, 4 Pi}];

The TwoAxisPlot, rescales two plots to appear to have the same range. The ranges of the functions are shown on the left and right sides of the frame:

TwoAxisPlot[{f_, g_}, {x_, x1_, x2_}] := 
 Module[{fgraph, ggraph, frange, grange, fticks, 
   gticks}, {fgraph, ggraph} = 
   MapIndexed[
    Plot[#, {x, x1, x2}, Axes -> True, 
      PlotStyle -> ColorData[1][#2[[1]]]] &, {f, g}]; {frange, 
    grange} = (PlotRange /. AbsoluteOptions[#, PlotRange])[[
      2]] & /@ {fgraph, ggraph}; fticks = N@FindDivisions[frange, 5];
  gticks = 
   Quiet@Transpose@{fticks, 
      ToString[NumberForm[#, 2], StandardForm] & /@ 
       Rescale[fticks, frange, grange]};
  Show[fgraph, 
   ggraph /. 
    Graphics[graph_, s___] :> 
     Graphics[
      GeometricTransformation[graph, 
       RescalingTransform[{{0, 1}, grange}, {{0, 1}, frange}]], s], 
   Axes -> False, Frame -> True, 
   FrameStyle -> {ColorData[1] /@ {1, 2}, {Automatic, Automatic}}, 
   FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}}]]

The combined plot illustrates the fact that for some and :

TwoAxisPlot[{Sin[x], 3 Sin[x] + 5 Cos[x]}, {x, 0, 4 Pi}]

! enter image description here

I hope this will help. Regards,…Jos

Note: See a further example with the function ‘Overlay’ on

TwoAxisPlot with ‘Overlay’