From: Sunt on
On Sep 14, 7:13 pm, Armand Tamzarian <mike.honeychu...(a)gmail.com>
wrote:
> Further to my post, here is atwoaxisDateListPlot. This is based on
> the TwoAXisListPlot code that floats around this group, which I
> believe originated from WRI tech support. The use of Frame->True
> breaks AbsoluteOptions (Ticks.FrameTicks) for many types of plots so
> by setting Axes->True, Frame->False we can get this to work and then
> set Frame->True after the relevant stuff has been extracted.
>
> Clear[TwoAxisDateListPlot];
>
> TwoAxisDateListPlot[f_List, g_List, opts : OptionsPattern[]] :=
> Module[{p1, p2, fm, fM, gm, gM, old, new, newg},
>
> p1 = DateListPlot[f, Axes -> True, Frame -> False,
> PlotRange -> Automatic];
> p2 = DateListPlot[g, Axes -> True, Frame -> False,
> PlotRange -> Automatic];
>
> {fm, fM} = AbsoluteOptions[p1, PlotRange][[1, 2, 2]];
> {gm, gM} = AbsoluteOptions[p2, PlotRange][[1, 2, 2]];
>
> old = AbsoluteOptions[p2, Ticks][[1, 2, 2]];
>
> new = Flatten[{Rescale[First[#1], {gm, gM}, {fm, fM}], Rest[#1]},
> 1] & /@ old;
>
> newg = {#[[1]], Rescale[#[[2]], {gm, gM}, {fm, fM}]} & /@ g;
>
> DateListPlot[{f, newg},
> Axes -> False,
> Frame -> True,
> FrameTicks -> {Automatic, Automatic, None, new},
> PlotRange -> {fm, fM},
> opts
> ]
> ]
>
> a test:
>
> f = Table[{{2009, i, 0}, RandomReal[{-2, 2}]}, {i, 10}];
> g = Table[{{2009, i, 0}, RandomReal[{-1000, 1000}]}, {i, 10}];
>
> TwoAxisDateListPlot[f, g, Joined -> True]
>
> Mike
>
> On Sep 11, 6:57 pm, Armand Tamzarian <mike.honeychu...(a)gmail.com>
> wrote:
> Show[pricesPlot]
>
>
>
>
>
> > This is easier ( to read at least):
>
> > spotPrices = First(a)Import["http://www.eia.doe.gov/emeu/international/
> > Crude1.xls","XLS"];
>
> > spotBrent = Cases[spotPrices[[All, {1, 3}]], {_List, x_?NumericQ}];
> > spotWTI = Cases[spotPrices[[All, {1, 4}]], {_List, x_?NumericQ}];
>
> > goldPrices = Import["http://www.lbma.org.uk/?area=stats&page=gold=
/
> > 2009dailygold","Data"];
>
> > goldPrices = Cases[goldPrices, {x_String, y__?NumericQ} :> {DateList
> > [x], y}, \[Infinity]];
>
> > >From here I don't exactly know how you want to make your plot (perhaps
>
> > scale the gold price?) or which price to choose but this is a simple
> > plot:
>
> > DateListPlot[{spotPriceWTI, goldPrices[[All, {1, 2}]]}, Joined ->
> > True, PlotRange -> All]
>
> > ------
>
> > If you wanted to only choose days in which you have data for both WTI
> > and gold you can use Intersection with a SameTest to create a subset
> > of the WTI data (or of course use Part or Take and make the choice
> > manually). General, but slow, case:
>
> > WTIsubset1=Quiet(a)Intersection[spotPriceWTI, goldPrices[[All, 1]],
> > SameTest -> (#1[[1]] == #2[[{1, 2, 3}]] &)]
>
> > Note that the {1,2,3} is necessary because the length of the date
> > lists differ for the oil and gold.
>
> > However if you only want 2009 data, which you would in this case:
>
> > WTIsubset2=Cases[spotPriceWTI, {{2009, __}, __}]
>
> > Ideally you'd want to have atwoaxisplot here but this has always
> > been problematic and breaks whenever I try to implement it with
> > DateListPlot. Some readers may have a working DateListPlottwoaxis
> > plot solution (?)
>
> > Mike

Great!
Thanks a lot!