Re: [Q] Graphics with 2 Y-axis
- To: mathgroup at smc.vnet.net
- Subject: [mg18450] Re: [mg18372] [Q] Graphics with 2 Y-axis
- From: BobHanlon at aol.com
- Date: Wed, 7 Jul 1999 00:11:34 -0400
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 6/30/99 8:55:51 PM, dtruong at irisa.fr writes: >How can one make a graphic with 2 Y-axis, either to >show 2 curves holding different value ranges or the same >curve using 2 scales (typically, percents and real value) > Following is my response to an earlier question which should provide some insight into an approach: Needs["Statistics`ContinuousDistributions`"]; mu = 2; sigma = 4; dist = NormalDistribution[mu, sigma]; Plot[{PDF[dist, x], CDF[dist, x]}, {x, mu-3sigma, mu+3sigma}]; (* plot removed *) To put the plots on the same size scale, the PDF values will be scaled by scale = CDF[dist, mu+3sigma]/PDF[dist, mu]//N 10.013 and the second y-axis will have its Ticks labeled accordingly. Simultaneously, the second x-axis will be labelled in standard deviations about the mean. red = RGBColor[1, 0, 0]; blue = RGBColor[0, 0, 1]; pdfTicks = Join[Table[{y, StyleForm[y/scale, FontColor -> red]}, {y, 0, 1.1, step = N[scale*Round[.2*(f = 10^(2+MantissaExponent[scale][[2]]))/ scale]/f]}], Table[{y,""}, {y,step/2, 1.1,step}]]; cdfTicks = Join[Table[{y, StyleForm[y, FontColor ->blue]}, {y, 0, 1, 0.2}], Table[{y,""}, {y, 0.1, 1, 0.2}]]; sigmaTicks = Join[{{mu-3sigma,"\[Mu]-3\[Sigma]"}, {mu-2sigma,"\[Mu]-2\[Sigma]"}, {mu-sigma,"\[Mu]-\[Sigma]"}, {mu,"\[Mu]"}, {mu+sigma,"\[Mu]+\[Sigma]"}, {mu+2sigma,"\[Mu]+2\[Sigma]"},{mu+3sigma,"\[Mu]+3\[Sigma]"}}, Table[{mu+k*sigma, ""}, {k, -2.5, 2.5}]]; Plot[{scale*PDF[dist, x], CDF[dist, x]}, {x, mu-3.1sigma, mu+3.1sigma}, ImageSize -> {420, 260}, PlotStyle -> {red,blue}, Axes -> False, Frame -> True, PlotLabel -> StyleForm["Normal Distribution\n", FontWeight -> "Bold", FontSize -> 12], FrameLabel -> {"x", "PDF\n", None, "CDF"}, FrameTicks -> {Automatic, pdfTicks, sigmaTicks,cdfTicks}, Epilog -> {Text["\[Mu] = " <> ToString[mu], {mu-2.75sigma, .9}, {-1, 0}], Text["\[Sigma] = " <> ToString[sigma], {mu-2.75sigma, .8}, {-1, 0}]}]; Bob Hanlon