Re: ListLogLinearPlot with two y-axis

*To*: mathgroup at smc.vnet.net*Subject*: [mg102575] Re: [mg102559] ListLogLinearPlot with two y-axis*From*: "David Park" <djmpark at comcast.net>*Date*: Sat, 15 Aug 2009 05:32:54 -0400 (EDT)*References*: <26148220.1250245897619.JavaMail.root@n11>

Here is an example of a two-axis log-linear plot using Presentations. We plot the two functions Sqrt[n] and n^2 over the domain 1 to 100 on a log scale. n^2 is scaled to fit in the Sqrt[n] range and a custom tick scale is generated for it on the right hand side of the frame. n^2 and its ticks are shown in red. Since we are dealing with underlying graphics primitives we also have to construct our own log tick scale for the n axis. Needs["Presentations`Master`"] The following generates two sets of data points for the functions. domainpoints = Union[Range[2, 20, 1]/2, 10 Range[20]/2] // N; dataset1 = Table[{n, Sqrt[n]}, {n, domainpoints}]; dataset2 = Table[{n, Rescale[n^2, {0, 10000}, {0, 10}]}, {n, domainpoints}]; The following specifies the custom tick scales we need. One is a log scale specifying the power range and the list of labeled and unlabeled ticks. The second is a linear scale going from 0 to 10000 in steps of 2000 with 4 unlabeled intervals between the labeled ticks. The values are shown in Red. xticks = CustomTicks[Log, {0, 2, {1, 2, 5}, {3, 4, 6, 7, 8, 9}}]; yticksright = CustomTicks[Rescale[#, {0, 10000}, {0, 10}] &, {0, 10000, 2000, 4}, CTNumberFunction -> (Style[#, Red] &)]; The following draws the plot with a text label within the plot. Draw2D[ {Text[Style["Two-Scale Plot", 14, Bold], Scaled[{.1, .9}], {-1, 0}], ListLogLinearDraw[dataset1, Joined -> True], Red, ListLogLinearDraw[dataset2, Joined -> True]}, AspectRatio -> .7, Frame -> True, FrameTicks -> {{Automatic, yticksright}, {xticks, xticks // NoTickLabels}}, FrameLabel -> {{Sqrt[n], Style[n^2, Red]}, {n, None}}, RotateLabel -> False, ImageSize -> 400] David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ From: pasQualle [mailto:pschulthess at googlemail.com] Hi everybody, I came across a solution for the plotting of continuous functions with two y-axis. I also found code to plot two lists with different ranges into one figure with two y-axis, but the thing I need is to plot two lists into one figure with two y-axis where the x-axis is in log. So, the solution for the lists looks like: TwoAxisListPlot[f_List, g_List, frange_, grange_, color1_, color2_, opts___?OptionQ] := Module[{old, new, scale, fm, fM, gm, gM, newg}, {fm, fM} = frange; {gm, gM} = grange; scale[var_] := ((var - gm) (fM - fm))/(gM - gm) + fm; old = AbsoluteOptions[ ListPlot[g, Frame -> True, PlotRange -> grange, DisplayFunction -> Identity], FrameTicks][[1, 2, 2]]; new = (Prepend[Rest[#1], scale[First[#1]]] &) /@ old; newg = Transpose[{Transpose[g][[1]], Map[scale, Transpose[g][[2]], {1, 2}]}]; ListLinePlot[{f, newg}, Frame -> True, FrameTicks -> {Automatic, Automatic, None, new}, PlotStyle -> {{color1}, {color2}}, FrameStyle -> {{}, {color1}, {}, {color2}}, PlotRange -> frange*(1 + .00 (fM - fm)), opts]] And to plot the lists: Labeled[Labeled[ TwoAxisListPlot[data1, data2, {5, 8.3}, {450, 460}, Red, Blue, Axes -> False, Joined -> {True, False}, PlotMarkers -> {Style[\[EmptyCircle], Red, Medium, Background -> White], Style[\[FilledUpTriangle], Blue, Medium]} ], {Style["X", FontFamily -> Times], Style["Y", Red, FontFamily -> Times]}, {Bottom, Left}], Style["Y-alt", Blue, FontFamily -> Times], Right] I'm really not that a Mathematica Pro to translate this for my purpose. Can anyone of you help me with this? I would really appreciate it. Thanks, Pascal