MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: TwoAxisListPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123825] Re: TwoAxisListPlot
  • From: Armand Tamzarian <mike.honeychurch at gmail.com>
  • Date: Wed, 21 Dec 2011 06:55:20 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jcpflc$qgc$1@smc.vnet.net>

On Dec 20, 7:06 pm, John <john.blackb... at rwth-aachen.de> wrote:
> Hi,
>
> I work with Mathematica 8.0.1.0 and was trying to customise the code for TwoAxisDateListPlot but failed (original code see below...I got it from Wolfram support). Here is what I wanted to do:
>
> I need to plot GDP against Exports for USA and Germany from 2007 to 2011 (all data is given in US-$). I chose GDP to be on the left-hand axes and Exports on the right-hand axes. Using TwoAxisDateListPlot works perfect, but: To compare the plots for USA and Germany with a blink of an eye it would be nice to have the same y-axis for both plots, like for example:
>
> {Min[Flatten[GdpUSA],GdpGermany]],Max[Flatten[GdpUSA],GdpGermany]]}
> and {Min[Flatten[ExportUSA],ExportGermany]],Max[Flatten[ExportUSA],ExportGermany]]}
>
> Here is what I changed:
>
> "TwoAxisDateListPlot[{data1_List, data2_List,PlotRange1_,PlotRange2_}
> ..
> {d1mn, d1mx} = PlotRange1;
>   {d2mn, d2mx} = PlotRange2;"
>
> I suppose in addition that I need to change something in the following, but don't know what:
>
> "rescl[num_] := Rescale[num, {d2mn, d2mx}, {d1mn, d1mx}];
>   newdata = Transpose[{data2A[[All, 1]], rescl[#] & /@ d2vals}];
>   {tcklocsM, tcklocsm} = FindDivisions[{d2mn, d2mx} + ((d2mx - d2mx) .05) {-1, 1}, {8,5}];"
>
> I found a comparable solution but wasn't able to implement their approach to the original code:http://alice.stfc.ac.uk/files/Software/Mathematica/TwoAxisListPlot.m
>
> By the way: Why should one implement "(d2mx - d2mx)" into code as it has always the value 0?
>
> Best regards
>
> --------------
>
> Original code from Wolfram support:
>
> TwoAxisDateListPlot[{data1_List, data2_List},opts : OptionsPattern[]] :=
=
> Module[{pltopts, d2vals, d1mn, d1mx, d2mn, d2mx, newdata, rescl,
>    tcklocsm, tcklocsM, d2tcks,bttm= Options[DateListPlot[data1],FrameTicks][[1,2,2,1]],data1A,data2A},
>   data1A=data1 /. {l_List, val_?NumericQ} :> {FromDate[l], val};
>   data2A=data2 /. {l_List, val_?NumericQ} :> {FromDate[l], val};
>   pltopts =
>    If[Select[{opts}, #[[1]] === PlotStyle &] === {},
>     Join[{opts}, {FrameStyle -> {{ColorData[1][1], ColorData[1][2]},
>         Automatic}}],
>     Join[{opts}, {FrameStyle -> {frameproc[opts], Automatic}}]];
>   d2vals = data2[[All, 2]];
>   {d1mn, d1mx} =
>   {Min[data1[[All, 2]]],
>      Max[data1[[All, 2]]]};
>   {d2mn, d2mx} = {Min[d2vals], Max[d2vals]};
>   rescl[num_] := Rescale[num, {d2mn, d2mx}, {d1mn, d1mx}];
>   newdata = Transpose[{data2A[[All, 1]], rescl[#] & /@ d2vals}];
>   {tcklocsM, tcklocsm} = FindDivisions[{d2mn, d2mx} + ((d2mx - d2mx) .05) {-1, 1}, {8,
>      5}];
>   d2tcks =
>    Join[MapThread[{rescl[#1],
>        NumberForm[N[#2], {5, 2}], {0.00675`, 0.`}, {GrayLevel[0.`],
>         AbsoluteThickness[0.125`]}} &, {tcklocsM,
>       tcklocsM}], {rescl[#],
>        "", {0.00375`, 0.`}, {GrayLevel[0.`],
>         AbsoluteThickness[0.125`]}} & /@ (Flatten[
>        tcklocsm[[All, 2 ;; -2]]])];
>   ListPlot[{data1A, newdata},
>   If[OptionValue[FrameTicks]===Automatic, FrameTicks -> {{Automatic, d2tcks}, {bttm, Automatic}},
>         OptionValue[FrameTicks]],
>    Evaluate@pltopts, Options[TwoAxisDateListPlot]]];


For some reason they won't provide us with a built version of this --
pretty much every other software on the planet has it -- requests for
it go back over a decade. There are many versions of code to do this
sort of thing floating around. AFAIK all have their limitations. This
is not particularly elegant but may be good enough for you:

http://library.wolfram.com/infocenter/MathSource/7507/

Mike

ps your code above uses "frameproc" which doesn't seem to be defined.
Is that the full cut and paste of what tech support gave you?



  • Prev by Date: Re: Variables within With statement
  • Next by Date: Re: Printing Mathematica Notebooks and WYSIWYG
  • Previous by thread: TwoAxisListPlot
  • Next by thread: Fast vs. Slow NonlinearModelFit models