Re: Multiple scales for Y axis of plot?
- To: mathgroup at smc.vnet.net
- Subject: [mg31110] Re: [mg31094] Multiple scales for Y axis of plot?
- From: BobHanlon at aol.com
- Date: Wed, 10 Oct 2001 03:43:24 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 2001/10/9 3:01:33 AM, crcarle at sandia.gov writes: >I have a typical multi-expression plot like this: > >Plot[ {f1, f2}, {x,a,b}, PlotStyle->{RGBColor[1,0,0], RGBColor[0,0,1]} >]. > >On the Y axis, I want to have a different scale for each of the two >functions. How can I generate another scaled Y axis adjacent to the >default one, or in general acheive this sort of thing? I anticipate a >lengthy process of building up all the graphics primitives, but before >I >figure all that out, I'm wondering if there is a reasonably easy way. > This makes use of AbsoluteOptions so I believe it requires version 4 or later. Needs["Graphics`Colors`"]; twoAxesPlot[{leftPlot_, rightPlot_}, {var_Symbol, varMin_?NumericQ, varMax_?NumericQ}, opts___] := Module[{lftPlt, rghtPlt, conv, lftTicks, rghtTicks, tcks, y, y1, y2, y3, y4}, lftPlt = Plot[leftPlot, {var, varMin, varMax}, DisplayFunction -> Identity, opts]; lftTicks = (Ticks /. AbsoluteOptions[lftPlt])[[2]]; tcks = First /@ lftTicks; y1 = Min[tcks]; y2 = Max[tcks]; rghtPlt = Plot[rightPlot, {var, varMin, varMax}, DisplayFunction -> Identity, opts]; rghtTicks = (Ticks /. AbsoluteOptions[rghtPlt])[[2]]; tcks = First /@ rghtTicks; y3 = Min[tcks]; y4 = Max[tcks]; rghtTicks = (rghtTicks /. {y_?NumericQ, z__} :> {conv[y], z}); conv[y_] := (y-y3)*(y2-y1)/(y4-y3) + y1; Plot[{leftPlot, conv[rightPlot]}, {var, varMin, varMax}, Frame -> True, Axes -> False, PlotStyle -> {Blue, Red}, FrameStyle -> {{}, {Blue}, {}, {Red}}, FrameTicks -> {Automatic, lftTicks, None, rghtTicks}, PlotRange -> {y1-0.02(y2-y1), y2+0.02(y2-y1)}, DisplayFunction -> $DisplayFunction, opts] ]; twoAxesPlot[{x, Exp[x]}, {x, 0, 10}]; Bob Hanlon Chantilly, VA USA