【问题标题】:Zoom region and display as a subplot within plot缩放区域并显示为图中的子图
【发布时间】:2011-03-23 23:31:21
【问题描述】:

是否可以放大一个区域并将其显示为同一图中的子图?这是我对手绘图形的原始尝试,以说明我的问题:

我可以考虑使用Plot,然后使用Epilog,但随后我迷失在定位和赋予情节自己的起源(当我在Plot上尝试Epilog时,新情节奠定了在旧的之上,使用旧的起源)。

另外,如果可以输入子图的定位就好了,因为不同的曲线有不同的“空白区域”可以用来定位图像。

我在几篇文章中看到了这一点,我可以在 MATLAB 中做到这一点,但我不知道如何在 mma 中做到这一点。

【问题讨论】:

标签: wolfram-mathematica


【解决方案1】:

使用插图。这是一个例子:

f[x_] = Sum[Sin[3^n x]/2^n, {n, 0, 20}];
x1 = x /. FindRoot[f[x] == -1, {x, -2.1}];
x2 = x /. FindRoot[f[x] == -1, {x, -1.1, -1}];
g = Plot[f[x], {x, x1, x2}, AspectRatio -> Automatic,
   Axes -> False, Frame -> True, FrameTicks -> None];
{y1, y2} = Last[PlotRange /. FullOptions[g]];
Plot[Sum[Sin[3^n x]/2^n, {n, 0, 20}], {x, -Pi, Pi},
 Epilog -> {Line[{
     {{x2, y2 + 0.1}, {-0.5, 0.5}}, {{x1, y2 + 0.1}, {-3.5, 0.5}},
     {{x1, y1}, {x2, y1}, {x2, y2 + 0.1}, {x1, y2 + 0.1}, {x1, 
       y1}}}],
   Inset[g, {-0.5, 0.5}, {Right, Bottom}, 3]},
 PlotRange -> {{-4, 4}, {-3, 3}}, AspectRatio -> Automatic]

【讨论】:

  • +1 自 4.0 版(1999 年发布)以来,FullOptions 已被 AbsoluteOptions 取代。 :D
  • 就此而言,我想知道为什么我不只使用选项?我猜旧习惯会慢慢消失。
  • 很好的例子!但在这种情况下,最好使用Prolog 而不是Epilog,以免与原始图重叠。
【解决方案2】:

并且,借用 belisarius' code,您还可以通过选择 x 轴上的位置交互式选择插图的焦点:

imgsz = 400;
f[x_] := Piecewise[{{Sin@x, Abs@x > .1}, {Sin[100 x], Abs[x] <= 0.1}}];

Manipulate[
 Plot[f[x], {x, -3, 3}, PlotRange -> {{-3, 3}, {-2, 5}}, 
  ImageSize -> imgsz, 
  Epilog -> 
   Inset[Plot[f[y], {y, p[[1]] - .3, p[[1]] + 0.3}, PlotStyle -> Red, 
     Axes -> False, Frame -> True, ImageSize -> imgsz/3], {1.5, 3}]],
 {{p, {0, 0}}, Locator, Appearance -> None}]

或者,如果您还想以交互方式放置插图:

Manipulate[
 Plot[f[x], {x, -3, 3}, PlotRange -> {{-3, 3}, {-2, 5}}, 
  ImageSize -> imgsz, 
  Epilog -> 
   Inset[Plot[f[y], {y, p[[1, 1]] - .3, p[[1, 1]] + 0.3}, 
     PlotStyle -> Red, Axes -> False, Frame -> True, 
     ImageSize -> imgsz/3], p[[2]]]],
 {{p, {{0, 0}, {1.5, 3}}}, Locator, Appearance -> None}]

编辑

基于 dbjohn 的问题的另一种选择:

imgsz = 400;
f[x_] := Piecewise[{{Sin@x, Abs@x > .1}, {Sin[100 x], Abs[x] <= 0.1}}];

Manipulate[
 Plot[f[x], {x, -3, 3}, PlotRange -> {{-3, 3}, {-2, 5}}, 
  ImageSize -> imgsz, 
  Epilog -> 
   Inset[Plot[f[y], {y, p[[1]] - .3, p[[1]] + 0.3}, PlotStyle -> Red, 
     Axes -> False, Frame -> True, ImageSize -> imgsz/3], 
    Scaled[zw]]], {{p, {0, 0}}, Locator, 
  Appearance -> None}, {{zw, {0.5, 0.5}, "Zoom window"}, Slider2D}]

【讨论】:

  • +1 好的解决方案。 @Sjoerd C. de Vries 使用它我注意到移动插图然后单击绘图会在您真的希望插图 x 轴焦点改变时“跳转”插图,也就是说它们有时会混淆。任何建议的改进来解决这个问题?也许是第二个定位器...
  • @dbjohn 是的,我也注意到了。点击总是转到最近的定位器。这可能意味着单击曲线可以移动缩放窗口,如果它比您之前缩放的曲线上的点更近。我曾考虑过使用修饰键(ctrl-click 等),但这会使它比我目前准备做的更复杂。另一种解决方案可能是使用 2D 滑块来选择缩放窗口的位置。
【解决方案3】:

只是一个启动:

imgsz = 400;
f[x_] := Piecewise[{{Sin@x, Abs@x > .1}, {Sin[100 x], Abs[x] <= 0.1}}];

Plot[f[x], {x, -3, 3}, PlotRange -> {{-5, 5}, {-5, 5}}, 
 ImageSize -> imgsz, Epilog ->
  Inset[Plot[f[y], {y, -.3, 0.3}, PlotStyle -> Red, Axes -> False, 
    Frame -> True, ImageSize -> imgsz/3], {3, 3}]]  

【讨论】:

    【解决方案4】:

    我发现这是一个需要更好的内置工具的领域。我一直在基于演示 here 研究这个解决方案。我更喜欢将缩放图像和未缩放图像分开,作为奖励,我添加了一个可展示的区域,可以放置相关的文本或方程式。对于不同的功能,可能需要手动调整纵横比。

    (f[x_] := x^2;
     ; xMin = -5; yMin = -5; xMax = 5; yMax = 5; 
     Manipulate[
      Grid[{{LocatorPane[{a}, 
          Plot[f[x], {x, xMin, xMax}, 
           PlotRange -> {{xMin, xMax }, {yMin, yMax}}, 
           ImageSize -> Medium, AspectRatio -> 1, AxesOrigin -> {0, 0}]], 
         Plot[f[x], {x, (a[[1]]) + xMin*mag, (a[[1]]) + xMax*mag}, 
          PlotRange -> {{(a[[1]]) + xMin*mag, (a[[1]]) + 
              xMax*mag}, {(a[[2]]) + yMin*mag, (a[[2]]) + yMax*mag}}, 
          ImageSize -> Medium, AspectRatio -> 1, AxesOrigin -> {0, 0}], 
         Item[StringForm["This is a suitable area to put any text.
           Value of A is :
           `1` ", a], Alignment -> {Left, Top}]}}, Frame -> All, 
       ItemSize -> All, 
       Spacings -> 5], {{a, {0, 0}}, {xMin, yMin}, {xMax, yMax}, Locator, 
       Appearance -> 
        Graphics[{Yellow, Opacity[.2], 
          Rectangle[Scaled[{.5 - (mag/2), .5 - (mag/2)}], 
           Scaled[{.5 + (mag/2), .5 + (mag/2)}]]}]}, {{mag, .5, 
        "Magnification"}, 0.01, 1, Appearance -> "Labeled"}])
    

    (f[x_] := 
       Piecewise[{{Sin@x, Abs@x > .1}, {Sin[100 x], Abs[x] <= 0.1}}];
     ; xMin = -3; yMin = -3; xMax = 3; yMax = 3; 
     Manipulate[
      Grid[{{LocatorPane[{a}, 
          Plot[f[x], {x, xMin, xMax}, 
           PlotRange -> {{xMin, xMax }, {yMin, yMax}}, 
           ImageSize -> Medium, AspectRatio -> 1, AxesOrigin -> {0, 0}]], 
         Plot[f[x], {x, (a[[1]]) + xMin*mag, (a[[1]]) + xMax*mag}, 
          PlotRange -> {(*{(a[[1]])+xMin*mag,(a[[1]])+xMax*
            mag},*){(a[[2]]) + yMin*mag, (a[[2]]) + yMax*mag}}, 
          ImageSize -> Medium, AspectRatio -> 1, AxesOrigin -> {0, 0}, 
          Frame -> True], 
         Item[StringForm["This is a suitable area to put any text.
           Value of A is :
           `1` ", a], Alignment -> {Left, Top}]}}, Frame -> All, 
       ItemSize -> All, 
       Spacings -> 5], {{a, {0, 0}}, {xMin, yMin}, {xMax, yMax}, Locator, 
       Appearance -> 
        Graphics[{Yellow, Opacity[.2], 
          Rectangle[Scaled[{.5 - (mag/2), .5 - (mag/2)}], 
           Scaled[{.5 + (mag/2), .5 + (mag/2)}]]}]}, {{mag, .06, 
        "Magnification"}, 0.01, 1, Appearance -> "Labeled"}])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 2019-05-04
      • 2011-08-02
      • 1970-01-01
      相关资源
      最近更新 更多