Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. optsall = {Axes -> False, Frame -> True, ImageSize -> 600,
  2. BaseStyle -> {Thick, FontSize -> 14}};
  3. opts1 = {ImagePadding -> {{Scaled[0.05], Scaled[0.11]}, {Scaled[0.04],
  4. Scaled[0.02]}},
  5. FrameStyle -> {Thick, {Thick, Blue}, Thick, Opacity[0]},
  6. FrameLabel -> {"x", "First y-label"}};
  7. opts2 = {ImagePadding -> {{Scaled[0.05], Scaled[0.11]}, {Scaled[0.04],
  8. Scaled[0.02]}},
  9. FrameStyle -> {Opacity[0], Opacity@0, Opacity@0, Green},
  10. FrameTicks -> All,
  11. FrameLabel -> ConstantArray["Second y-label", 4]};
  12. opts3 = {ImagePadding -> {{Scaled[0.11], Scaled[0.05]}, {Scaled[0.04],
  13. Scaled[0.02]}},
  14. FrameStyle -> {Opacity[0], Opacity@0, Opacity@0, Red},
  15. FrameTicks -> All, FrameLabel -> ConstantArray["Third y-label", 4]};
  16. Overlay[{
  17. Plot[{x, Rescale[x^2, {0, 100}, {0, 10}],
  18. Rescale[x^3, {0, 1000}, {0, 10}]}, {x, 0, 10},
  19. PlotStyle -> {Blue, Green, Red},
  20. ##, PlotLegends ->
  21. Placed[LineLegend[{"y = x", "y = x^2", "y = x^3"},
  22. LegendFunction -> (Framed[#] &)], Scaled[{0.15, 0.8}]]] & @@
  23. Join[optsall, opts1],
  24. Plot[x^2, {x, 0, 10}, PlotStyle -> None,
  25. ##] & @@ Join[optsall, opts2],
  26. Plot[x^3, {x, 0, 10}, PlotStyle -> None, ##] & @@
  27. Join[optsall, opts3]
  28.  
  29. }]
  30.  
  31. Clear[threeyaxisplot];
  32. threeyaxisplot[{f1_, f1label_}, {f2_, f2label_}, {f3_, f3label_},
  33. range : {var_Symbol, vmin_?NumericQ, vmax_?NumericQ}] :=
  34. Module[{plot1, plot2, plot3, p1yrng, p2yrng, p3yrng, p2yaxis,
  35. p3yaxis},
  36. {
  37. {plot1, plot2, plot3} =
  38. Plot[#[var], range, Axes -> False,
  39. Frame -> {True, True, False, False},
  40. PlotRangeClipping -> False] & /@ {f1, f2, f3}
  41. };
  42. {p2yaxis, p3yaxis} =
  43. Plot[(First@#)[var], range, Axes -> False,
  44. Frame -> {False, True, False, False}, PlotStyle -> White,
  45. FrameLabel -> {None, Last@#}] & /@ {{f2, f2label}, {f3,
  46. f3label}};
  47. {p1yrng, p2yrng, p3yrng} =
  48. Last@(PlotRange /. Options[#, PlotRange]) & /@ {plot1, plot2,
  49. plot3};
  50. Plot[{f1[var], Rescale[f2[var], p2yrng, p1yrng],
  51. Rescale[f3[var], p3yrng, p1yrng]}, range,
  52. PlotRangeClipping -> False,
  53. Axes -> False, Frame -> {True, True, False, False},
  54. FrameLabel -> {None, f1label},
  55. Epilog -> {
  56. Inset[p2yaxis, Scaled@{1.6, 0.5}, Scaled@{0.5, 0.5}, Scaled@1.07],
  57. Inset[p3yaxis, Scaled@{1.85, 0.5}, Scaled@{0.5, 0.5},
  58. Scaled@1.07]},
  59. ImagePadding -> {{Automatic, 130}, {Automatic, Automatic}}]
  60. ]
  61. out = threeyaxisplot[{# &, "function1"}, {#^2 &, "function2"}, {#^3 &,
  62. "function3"}, {x, 0, 10}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement