Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- optsall = {Axes -> False, Frame -> True, ImageSize -> 600,
- BaseStyle -> {Thick, FontSize -> 14}};
- opts1 = {ImagePadding -> {{Scaled[0.05], Scaled[0.11]}, {Scaled[0.04],
- Scaled[0.02]}},
- FrameStyle -> {Thick, {Thick, Blue}, Thick, Opacity[0]},
- FrameLabel -> {"x", "First y-label"}};
- opts2 = {ImagePadding -> {{Scaled[0.05], Scaled[0.11]}, {Scaled[0.04],
- Scaled[0.02]}},
- FrameStyle -> {Opacity[0], Opacity@0, Opacity@0, Green},
- FrameTicks -> All,
- FrameLabel -> ConstantArray["Second y-label", 4]};
- opts3 = {ImagePadding -> {{Scaled[0.11], Scaled[0.05]}, {Scaled[0.04],
- Scaled[0.02]}},
- FrameStyle -> {Opacity[0], Opacity@0, Opacity@0, Red},
- FrameTicks -> All, FrameLabel -> ConstantArray["Third y-label", 4]};
- Overlay[{
- Plot[{x, Rescale[x^2, {0, 100}, {0, 10}],
- Rescale[x^3, {0, 1000}, {0, 10}]}, {x, 0, 10},
- PlotStyle -> {Blue, Green, Red},
- ##, PlotLegends ->
- Placed[LineLegend[{"y = x", "y = x^2", "y = x^3"},
- LegendFunction -> (Framed[#] &)], Scaled[{0.15, 0.8}]]] & @@
- Join[optsall, opts1],
- Plot[x^2, {x, 0, 10}, PlotStyle -> None,
- ##] & @@ Join[optsall, opts2],
- Plot[x^3, {x, 0, 10}, PlotStyle -> None, ##] & @@
- Join[optsall, opts3]
- }]
- Clear[threeyaxisplot];
- threeyaxisplot[{f1_, f1label_}, {f2_, f2label_}, {f3_, f3label_},
- range : {var_Symbol, vmin_?NumericQ, vmax_?NumericQ}] :=
- Module[{plot1, plot2, plot3, p1yrng, p2yrng, p3yrng, p2yaxis,
- p3yaxis},
- {
- {plot1, plot2, plot3} =
- Plot[#[var], range, Axes -> False,
- Frame -> {True, True, False, False},
- PlotRangeClipping -> False] & /@ {f1, f2, f3}
- };
- {p2yaxis, p3yaxis} =
- Plot[(First@#)[var], range, Axes -> False,
- Frame -> {False, True, False, False}, PlotStyle -> White,
- FrameLabel -> {None, Last@#}] & /@ {{f2, f2label}, {f3,
- f3label}};
- {p1yrng, p2yrng, p3yrng} =
- Last@(PlotRange /. Options[#, PlotRange]) & /@ {plot1, plot2,
- plot3};
- Plot[{f1[var], Rescale[f2[var], p2yrng, p1yrng],
- Rescale[f3[var], p3yrng, p1yrng]}, range,
- PlotRangeClipping -> False,
- Axes -> False, Frame -> {True, True, False, False},
- FrameLabel -> {None, f1label},
- Epilog -> {
- Inset[p2yaxis, Scaled@{1.6, 0.5}, Scaled@{0.5, 0.5}, Scaled@1.07],
- Inset[p3yaxis, Scaled@{1.85, 0.5}, Scaled@{0.5, 0.5},
- Scaled@1.07]},
- ImagePadding -> {{Automatic, 130}, {Automatic, Automatic}}]
- ]
- out = threeyaxisplot[{# &, "function1"}, {#^2 &, "function2"}, {#^3 &,
- "function3"}, {x, 0, 10}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement