Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7364 > unrolled thread

TwoAxisListPlot

Started byJohn <john.blackburn@rwth-aachen.de>
First post2011-12-20 08:06 +0000
Last post2011-12-21 11:57 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  TwoAxisListPlot John <john.blackburn@rwth-aachen.de> - 2011-12-20 08:06 +0000
    Re: TwoAxisListPlot Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-12-21 11:57 +0000

#7364 — TwoAxisListPlot

FromJohn <john.blackburn@rwth-aachen.de>
Date2011-12-20 08:06 +0000
SubjectTwoAxisListPlot
Message-ID<jcpflc$qgc$1@smc.vnet.net>
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]]];

[toc] | [next] | [standalone]


#7382

FromArmand Tamzarian <mike.honeychurch@gmail.com>
Date2011-12-21 11:57 +0000
Message-ID<jcshit$298$1@smc.vnet.net>
In reply to#7364
On Dec 20, 7:06 pm, John <john.blackb...@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?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web