Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. Options[extraAxisPlot] = {"AxisType" -> "xAxis",
  2. "AxisOptions" -> {}, "ExtraEpilog" -> {}};
  3. extraAxisPlot[plot_, {axisStart_, axisFinish_}, {xpos_, ypos_},
  4. OptionsPattern[]] := Module[
  5. {printerPointsPlotRange, realImageDimensions, realPlotRange,
  6. plotRangeRatio,
  7. axisplotrange, axisxrange, axisaxes, insetpos, axis},
  8. printerPointsPlotRange = (#[[2]] - #[[1]] &)@(Rasterize[
  9. Show[#, Epilog -> {Annotation[
  10. Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]],
  11. "Two",
  12. "Region"]}], "Regions"][[-1, 2]]) &;
  13. realImageDimensions = (#[[2]] - #[[1]] &)@(Rasterize[
  14. Show[#, Epilog -> {Annotation[
  15.  
  16. Rectangle[ImageScaled[{0, 0}], ImageScaled[{1, 1}]],
  17. "Two", "Region"]}], "Regions"][[-1, 2]]) &;
  18. realPlotRange =
  19. Module[{padding =
  20.  
  21. Total /@ (Options[#, PlotRangePadding][[-1, 2]] /.
  22. None -> 0),
  23. baserange = (#[[2]] - #[[1]] &) /@ PlotRange[#], range},
  24.  
  25. range = (baserange + padding) /. {a_ Scaled[b_] -> Scaled[a b],
  26. Scaled[a_] + Scaled[b_] -> Scaled[a + b]} /. {a_ +
  27. Scaled[b_] -> a/(1 - b)};
  28. range] &;
  29. plotRangeRatio = realPlotRange[#1]/realPlotRange[#2] &;
  30. {axisplotrange, axisxrange, axisaxes, insetpos} =
  31. Which[OptionValue["AxisType"] == "xAxis",
  32. {{{axisStart, axisFinish}, Automatic}, {axisStart,
  33. axisFinish}, {True, False}, {axisStart, 0}},
  34. OptionValue["AxisType"] == "yAxis",
  35. {{Automatic, {axisStart, axisFinish}}, {0, 1}, {False,
  36. True}, {0,
  37. axisStart}},
  38. OptionValue["AxisType"] == "Both",
  39. {Transpose@{axisStart, axisFinish}, {axisStart[[1]],
  40. axisFinish[[1]]}, {True, True}, axisStart},
  41. True,
  42. Print["Invalid axis type"];
  43. Abort[] (*If the option isn't one of the three axis types,
  44. then quit the code*)];
  45.  
  46. axis = Plot[Null, {x, axisxrange[[1]], axisxrange[[2]]},
  47. PlotRange -> axisplotrange, Axes -> axisaxes,
  48. Evaluate@OptionValue["AxisOptions"]];
  49.  
  50. Show[plot,
  51. Epilog -> { Evaluate@OptionValue["ExtraEpilog"],
  52. Inset[Show[axis,
  53. ImageSize ->
  54. plotRangeRatio[axis, plot] printerPointsPlotRange[
  55. plot] + (realImageDimensions[axis] -
  56. printerPointsPlotRange[axis]),
  57. AspectRatio -> (Last[#]/First[#] &)@(plotRangeRatio[axis,
  58. plot] printerPointsPlotRange[plot])], {xpos, ypos},
  59. insetpos, Automatic]}]
  60. ];
  61.  
  62. test={{0.875,0.000361069,-0.137},{0.9,-0.000429778,-0.1096},{0.925,-0.000102596,-0.0822},{0.95,-0.000234415,-0.0548},{0.975,-0.00066855,-0.0274},{1.,-0.00114038,0},{1.025,0.00278551,0.0274},{1.05,-0.00148313,0.0548},{1.075,0.00132836,0.0822},{1.1,-0.000164138,0.1096},{1.125,-0.00036032,0.137}};
  63.  
  64. plot = ListLinePlot[test[[All,;;2]],Frame->True,FrameTicks->{{Automatic,Automatic},{Automatic,None}}];
  65. extraAxisPlot[plot,{-.13,.13},{.875,.0031}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement