1

Till this date Mathematica is devoid of a dedicated function which can be used to zoom over a specified region of a plot and placed the zoomed sub-plot inside the main plot as an inset. (usually found in research articles)

At present I'm using combination of multiple chunks like:

  • Plot (for plotting the graphs for main range & then for zoomed sub-range)
  • Epilog / Prolog with Inset (for placing the sub-plot inside the main plot at a specified location)

enter image description here

Any update or techniques, will help us a lot.

1 Answers1

1

Here is a function that I wrote long time ago that let you zoom into a graphics. You may then copy the zoomed part and inset it into your original graphics.

"Zoom2D" takes a graphics as input like e.g. "Zoom2D[g]".

Zoom2D[g0_] := Module[{g, g1, pp1, pp2}, tt = g0;
  If[! MatchQ[Head[g0], Graphics | GraphicsBox], 
   CreateDialog[{TextCell["Zoom: No Input available."], 
     DefaultButton[]}]; Return[];
   ];
  g = If[Head[g0] =!= Graphics, 
    ReplaceAll[g0, {GraphicsBox -> Graphics}], g0];
  g = g /. NCache[_, x_] :> x;
  {pp1, pp2} = (PlotRange /. AbsoluteOptions[g]) // Transpose;
  g1 = DynamicModule[{p1 = pp1, p2 = pp2, lp = {0, 0}, aspect = 1}, 
    Column[{LocatorPane[Dynamic[{p1, p2}], 
       Show[{g, 
         Graphics[{Opacity[0.1], 
           Rectangle[Dynamic[p1], Dynamic[p2]]}]}, 
        ImageSize -> Small]], 
      EventHandler[
       Show[g, PlotRange :> Dynamic[Transpose[{p1, p2}]], 
        Frame -> True, ImageSize -> Full, 
        AspectRatio -> 
         Dynamic[aspect]], {"MouseClicked" :> (lp = 
           MousePosition["Graphics"])}], Dynamic[lp]
      , Row[{TextCell["AspectRatio fixed: "], 
        Checkbox[Dynamic[aspect], {Automatic, 1}]}]}, Center]];
  CreateDocument[g1, WindowSize -> {Small, All}, 
   WindowTitle -> "Zoom", WindowElements -> {}, 
   WindowFrame -> "Palette"]

![enter image description here

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
  • Thanks for the effort, but the effort is too much just for zooming a section. There must be some simple way or Mathematica & Co. have to do something about it. – Kumar Gaurav Sagar Oct 21 '23 at 12:23