Re: two y-axes with different scaling
- To: mathgroup at smc.vnet.net
- Subject: [mg95874] Re: two y-axes with different scaling
- From: "Jaccard Florian" <Florian.Jaccard at he-arc.ch>
- Date: Thu, 29 Jan 2009 05:52:30 -0500 (EST)
- References: <200901281144.GAA22135@smc.vnet.net>
Hello Joerg,
If you look in the archives, you will see that this question has often come around.
There are several ways of doing it.
For example "by hand" (to plot y=sin(x) and y=3cos(x) with same looking amplitude):
d1 = Plot[{Sin[x], Cos[x]}, {x, 0, 10}, PlotRange -> {{0, 10}, {-1, 1}},
PlotStyle -> {Blue, Red}, Epilog -> {Text[Style["Sin(x)", FontColor -> Blue],
{2, 0.8}, Background -> White], Text[Style["3 Cos(x)", FontColor -> Red],
{5.2, 0.8}, Background -> White]}, DisplayFunction -> Identity];
Show[FullGraphics[d1] /. {{GrayLevel[0.], AbsoluteThickness[0.125],
Line[{{0., b_}, {c_, d_}}]} -> {Red, AbsoluteThickness[0.125],
Line[{{10, b}, {10 + c, d}}]}, Text[a_, {b_, c_}, {1., 0.}] ->
{Text[Style[3*a, FontColor -> Red], {b + 10, c}, {-1.5, 0}],
Text[Style[a, FontColor -> Blue], {b, c}, {1, 0}]}},
Graphics[{Red, Line[{{10, -1}, {10, 1}}]}], PlotRange -> {{-1.5, 12}, {-1.1, 1.1}}]
Or using what was on http://support.wolfram.com/mathematica/graphics/2d/twoaxisgraph.html (but I can't find it anymore) :
TwoAxisPlot[{f_, g_}, {x_, min_, max_}, frange_, grange_, (opts___)?OptionQ] :=
Module[{old, new, scale, pts, gstuff, fstuff}, {fm, fM} = frange;
{gm, gM} = grange; scale[var_] = ((var - gm)*(fM - fm))/(gM - gm) + fm;
old = AbsoluteOptions[Plot[g, {x, min, max}, Frame -> True, PlotRange -> grange,
DisplayFunction -> Identity], FrameTicks][[1,2,2]];
new = (Prepend[Rest[#1], scale[First[#1]]] & ) /@ old;
Plot[{f, scale[g]}, {x, min, max}, Frame -> True,
PlotRange -> frange + {0, 0.05*(fM - fm)}, FrameTicks ->
{Automatic, Automatic, None, new}, PlotStyle ->
{{Thickness[0.01], RGBColor[1, 0, 0]}, {Thickness[0.01], RGBColor[0, 1, 0]}},
FrameStyle -> {{}, {RGBColor[1, 0, 0]}, {}, {RGBColor[0, 1, 0]}}, opts]]
Example :
v[t_] := 3*t - 2
s[t_] := (3/2)*t^2 - 2*t
TwoAxisPlot[{v[t], s[t]}, {t, -10, 12}, {-50, 50}, {-100, 200},
GridLines -> {Range[-10, 12, 2], None},
Epilog -> {Text["v(t)", {-5, -20}, Background -> White],
Text["s(t)", {-8, 20}, Background -> White]}]
Regards
F.Jaccard
________________________________
De: Joerg [mailto:schaber at biologie.hu-berlin.de]
Date: mer. 28.01.2009 12:44
=C0: mathgroup at smc.vnet.net
Objet : [mg95861] two y-axes with different scaling
Hi,
I want to combine two 2-D plots into one.
However, I want to have two different
y-axes. One on the left and one two the right,
with different ticklabels, respectively.
How do I do that? I couln't find any
example in the help files.
Thanks,
joerg
- References:
- two y-axes with different scaling
- From: Joerg <schaber@biologie.hu-berlin.de>
- two y-axes with different scaling