Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Options[extraAxisPlot] = {"AxisType" -> "xAxis",
- "AxisOptions" -> {}, "ExtraEpilog" -> {}};
- extraAxisPlot[plot_, {axisStart_, axisFinish_}, {xpos_, ypos_},
- OptionsPattern[]] := Module[
- {printerPointsPlotRange, realImageDimensions, realPlotRange,
- plotRangeRatio,
- axisplotrange, axisxrange, axisaxes, insetpos, axis},
- printerPointsPlotRange = (#[[2]] - #[[1]] &)@(Rasterize[
- Show[#, Epilog -> {Annotation[
- Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]],
- "Two",
- "Region"]}], "Regions"][[-1, 2]]) &;
- realImageDimensions = (#[[2]] - #[[1]] &)@(Rasterize[
- Show[#, Epilog -> {Annotation[
- Rectangle[ImageScaled[{0, 0}], ImageScaled[{1, 1}]],
- "Two", "Region"]}], "Regions"][[-1, 2]]) &;
- realPlotRange =
- Module[{padding =
- Total /@ (Options[#, PlotRangePadding][[-1, 2]] /.
- None -> 0),
- baserange = (#[[2]] - #[[1]] &) /@ PlotRange[#], range},
- range = (baserange + padding) /. {a_ Scaled[b_] -> Scaled[a b],
- Scaled[a_] + Scaled[b_] -> Scaled[a + b]} /. {a_ +
- Scaled[b_] -> a/(1 - b)};
- range] &;
- plotRangeRatio = realPlotRange[#1]/realPlotRange[#2] &;
- {axisplotrange, axisxrange, axisaxes, insetpos} =
- Which[OptionValue["AxisType"] == "xAxis",
- {{{axisStart, axisFinish}, Automatic}, {axisStart,
- axisFinish}, {True, False}, {axisStart, 0}},
- OptionValue["AxisType"] == "yAxis",
- {{Automatic, {axisStart, axisFinish}}, {0, 1}, {False,
- True}, {0,
- axisStart}},
- OptionValue["AxisType"] == "Both",
- {Transpose@{axisStart, axisFinish}, {axisStart[[1]],
- axisFinish[[1]]}, {True, True}, axisStart},
- True,
- Print["Invalid axis type"];
- Abort[] (*If the option isn't one of the three axis types,
- then quit the code*)];
- axis = Plot[Null, {x, axisxrange[[1]], axisxrange[[2]]},
- PlotRange -> axisplotrange, Axes -> axisaxes,
- Evaluate@OptionValue["AxisOptions"]];
- Show[plot,
- Epilog -> { Evaluate@OptionValue["ExtraEpilog"],
- Inset[Show[axis,
- ImageSize ->
- plotRangeRatio[axis, plot] printerPointsPlotRange[
- plot] + (realImageDimensions[axis] -
- printerPointsPlotRange[axis]),
- AspectRatio -> (Last[#]/First[#] &)@(plotRangeRatio[axis,
- plot] printerPointsPlotRange[plot])], {xpos, ypos},
- insetpos, Automatic]}]
- ];
- 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}};
- plot = ListLinePlot[test[[All,;;2]],Frame->True,FrameTicks->{{Automatic,Automatic},{Automatic,None}}];
- extraAxisPlot[plot,{-.13,.13},{.875,.0031}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement