Skip to main content
deleted 1 character in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k
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] & 
Show[gr1, Epilog -> Inset[Show[gr2, ImageSize -> plotRangeRatio[gr2, gr1] printerPointsPlotRange[gr1] + (realImageDimensions[gr2] - printerPointsPlotRange[gr2]), AspectRatio -> (Last[#]/First[#] &)@ (plotRangeRatio[gr2, gr1] printerPointsPlotRange[gr1])], {0, 0}, {0, 0}, Automatic]}]Automatic]] 
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] & 
Show[gr1, Epilog -> Inset[Show[gr2, ImageSize -> plotRangeRatio[gr2, gr1] printerPointsPlotRange[gr1] + (realImageDimensions[gr2] - printerPointsPlotRange[gr2]), AspectRatio -> (Last[#]/First[#] &)@ (plotRangeRatio[gr2, gr1] printerPointsPlotRange[gr1])], {0, 0}, {0, 0}, Automatic]}] 
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] & 
Show[gr1, Epilog -> Inset[Show[gr2, ImageSize -> plotRangeRatio[gr2, gr1] printerPointsPlotRange[gr1] + (realImageDimensions[gr2] - printerPointsPlotRange[gr2]), AspectRatio -> (Last[#]/First[#] &)@ (plotRangeRatio[gr2, gr1] printerPointsPlotRange[gr1])], {0, 0}, {0, 0}, Automatic]] 
Generalized approach to non-zero PlotRangePadding
Source Link
LLlAMnYP
  • 11.6k
  • 28
  • 68

This approach does not account for PlotRangingPadding being different from zero. I'll update as soon as I can to remedy this.

As per the comment section of the OP I assume that the image padding is a constant number of printer points, though it is not necessarily known. I use the rasterize trick to obtain the size of the plotting range in printer points:

Ratio of the plot rangesI implement a modified version of two plots:PlotRange to account for PlotRangePadding.

plotRangeRatiorealPlotRange = Module[ {padding = Total /@ (Options[#, PlotRangePadding][[-1, 2]] /. None -> 0), baserange = (#[[2]] - #[[1]] &) /@ PlotRange[#1]PlotRange[#], range}, range = (baserange + padding) /.   {a_ Scaled[b_] -> Scaled[a b], Scaled[a_] + Scaled[b_] -> Scaled[a + b]} /.    {a_ + (Scaled[b_] -> a/(#[[2]]1 - #[[1]]b)};  range] &) 

It appears to fail for mixed specifications, such as {{1,Scaled[.1]},{Scaled[.02],Scaled[.02]}}. However if the left and right paddings are both given either in Scaled form or in the coordinates of the plot and the same holds for the top and bottom padding specs, the function works fine.

plotRangeRatio /@= PlotRange[#2])realPlotRange[#1]/realPlotRange[#2] & 

This approach does not account for PlotRangingPadding being different from zero. I'll update as soon as I can to remedy this.

As per the comment section of the OP I assume that the image padding is a constant number of printer points, though it is not necessarily known. I use the rasterize trick to obtain the size of the plotting range in printer points:

Ratio of the plot ranges of two plots:

plotRangeRatio = ((#[[2]] - #[[1]] &) /@ PlotRange[#1])/ ((#[[2]] - #[[1]] &) /@ PlotRange[#2]) & 

As per the comment section of the OP I assume that the image padding is a constant number of printer points, though it is not necessarily known. I use the rasterize trick to obtain the size of the plotting range in printer points:

I implement a modified version of PlotRange to account for PlotRangePadding.

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] & 

It appears to fail for mixed specifications, such as {{1,Scaled[.1]},{Scaled[.02],Scaled[.02]}}. However if the left and right paddings are both given either in Scaled form or in the coordinates of the plot and the same holds for the top and bottom padding specs, the function works fine.

plotRangeRatio = realPlotRange[#1]/realPlotRange[#2] & 
added 135 characters in body
Source Link
LLlAMnYP
  • 11.6k
  • 28
  • 68

This approach does not account for PlotRangingPadding being different from zero. I'll update as soon as I can to remedy this.

As per the comment section of the OP I assume that the image padding is a constant number of printer points, though it is not necessarily known. I use the rasterize trick to obtain the size of the plotting range in printer points:

As per the comment section of the OP I assume that the image padding is a constant number of printer points, though it is not necessarily known. I use the rasterize trick to obtain the size of the plotting range in printer points:

This approach does not account for PlotRangingPadding being different from zero. I'll update as soon as I can to remedy this.

As per the comment section of the OP I assume that the image padding is a constant number of printer points, though it is not necessarily known. I use the rasterize trick to obtain the size of the plotting range in printer points:

Source Link
LLlAMnYP
  • 11.6k
  • 28
  • 68
Loading