TwoAxisListPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg123807] TwoAxisListPlot
- From: John <john.blackburn at rwth-aachen.de>
- Date: Tue, 20 Dec 2011 03:04:00 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
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]]];