- 积分
- 0
- 注册时间
- 2010-8-17
- 仿真币
-
- 最后登录
- 1970-1-1
|
发表于 2011-5-18 20:55:15
|
显示全部楼层
来自 清华大学
本帖最后由 sunt05 于 2011-5-18 20:57 编辑
试试这个~
可以参考这个帖子:
https://groups.google.com/d/msg/comp.soft-sys.math.mathematica/CKE9Ghn43x8/F1_JnIbCYjsJ
- 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]]
- Clear[TwoAxisReverseDateListPlot];
- TwoAxisReverseDateListPlot[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[{fM + fm - Rescale[First[#1], {gm, gM}, {fm, fM}],
- Rest[#1]}, 1] & /@ old;
- newg = {#[[1]], fM + fm - Rescale[#[[2]], {gm, gM}, {fm, fM}]} & /@
- g;
- DateListPlot[{f, newg}, Axes -> False, Frame -> True,
- FrameTicks -> {Automatic, Automatic, None, new},
- PlotRange -> {fm, fM}, opts]]
- TwoAxisReverseDateListPlot[f_List, g_List, r_,
- opts : OptionsPattern[]] :=
- Module[{p1, p2, gg, pg2, m, M, fm, fM, gm, gM, ggm, ggM, old, new,
- newg}, p1 =
- DateListPlot[f, Axes -> True, Frame -> False,
- PlotRange -> Automatic];
- gg = g;
- gg[[All, 2]] /= 1 - r;
- p2 = DateListPlot[g, Axes -> True, Frame -> False,
- PlotRange -> Automatic];
- pg2 = DateListPlot[gg, Axes -> True, Frame -> False,
- PlotRange -> Automatic];
- {fm, fM} = AbsoluteOptions[p1, PlotRange][[1, 2, 2]];
- {m, M} = {fm, 1/r fM};
- {gm, gM} = AbsoluteOptions[p2, PlotRange][[1, 2, 2]];
- {ggm, ggM} = AbsoluteOptions[pg2, PlotRange][[1, 2, 2]];
- old = AbsoluteOptions[pg2, Ticks][[1, 2, 2]];
- new = Flatten[{(M + m - Rescale[First[#1], {ggm, ggM}, {m, M}]),
- Rest[#1]}, 1] & /@ old;
- newg = {#[[
- 1]], (M + m - (1 - r) Rescale[#[[2]], {gm, gM}, {m, M}])} & /@
- g;
- DateListPlot[{f, newg}, Axes -> False, Frame -> True,
- FrameTicks -> {Automatic, new, None, All}, PlotRange -> {m, M},
- opts]]
复制代码 |
|