如何使用 LevelScheme 在 Mathematica 中创建子图?

发布于 2024-10-26 15:46:35 字数 369 浏览 1 评论 0原文

以 MATLAB 中生成的以下任意图形为例。基本想法是我有一个等高线图,我想在右侧的子图中展示从中选择的切片。 mma中有相当于subplot的吗?

我现在所做的工作是只绘制带有切片和箭头的等高线图以及分别的两个切片图,然后将它们放在乳胶中。不过,我希望能够在 mma 内做到这一点。我该怎么做呢?

我的一个想法是生成一个具有完整垂直和垂直方向的等高线图。半水平纵横比,这两个图具有半垂直和半垂直的比例。一半水平宽高比,然后使用 GraphicsGrid 将它们对齐。但这仍然给我提供了列表形式的图,而不是复合图。这是唯一的方法还是有更好、更优雅的方法?

在此处输入图像描述

Consider the following arbitrary figure generated in MATLAB as an example. The basic idea is that I have a contour plot and I want to showcase selected slices from it in subplots on the right. Is there an equivalent of subplot in mma?

The work around that I have right now is to have just the contour plot with the slices and the arrows and the two slice-plots separately and then put them together in latex. However, I'd like to be able to do this within mma. How do I go about doing this?

An idea that I had is to generate a the contour plot with a full vertical & half horizontal aspect ratio, the two plots with half vertical & half horizontal aspect ratio, and then use GraphicsGrid to align them up. But this still gave me the plots as a list, not a composite figure. Is this the only way or is there a nicer, more elegant way of doing it?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╰ゝ天使的微笑 2024-11-02 15:46:35

我知道 LevelScheme 中的 Multipanel 可能可以让你做什么你想要的 - 但我对此没有太多经验,并且文档中的示例相当稀疏。
我已经将示例之一粘贴到这个SO中答案,所以看看那里,看看你的想法!


这是我对 GraphicsGrid 的尝试。
Multipanel 可以做但 GraphicsGrid 不能做的事情
是让您使用不同的列/行大小。
这意味着我很难以编程方式绘制箭头,而是使用“绘图工具”面板 (:D)

With[{yslice1 = .5, yslice2 = -.8},
 GraphicsGrid[
  {{DensityPlot[Sin[15 x y], {x, -1, 1}, {y, -1, 1}, 
     ColorFunction -> "PlumColors", AspectRatio -> 2,
     Epilog -> {Dashed, White, Line[{{-1, yslice1}, {1, yslice1}}], 
       Line[{{-1, yslice2}, {1, yslice2}}]}],
    Plot[Sin[15 x yslice1], {x, -1, 1}, Axes -> False, Frame -> True]},
   {SpanFromAbove,
    Plot[Sin[15 x yslice2], {x, -1, 1}, Axes -> False, 
     Frame -> True]}},
  Spacings -> {Scaled[0.2], Scaled[0.0]}]]


编辑:

这里使用 LevelScheme 进行相同的操作,请注意框架对齐。
应该可以添加箭头 - 因为 LevelScheme 有很多新的箭头指令 - 但我将把它作为家庭作业问题!

<< "LevelScheme`"
{yslice1 = .5, yslice2 = -.8};
Figure[{
  SetOptions[Multipanel, 
   ShowTickLabels -> {True, False, False, True}, Background -> Wheat,
   PanelLetterFontSize -> 10, Margin -> {{40, 40}, {40, 0}}],
  Multipanel[{{0, 1}, {0, 1}}, {2, 2},
   XPlotRanges -> {-1, 1}, YPlotRanges -> {-1, 1},
   XFrameLabels -> textit["x"], YFrameLabels -> textit["y"],
   TickFontSize -> 10, XFrameTicks -> LinTicks[-1, 1, .5, 4], 
   YFrameTicks -> LinTicks[-1, 1, .5, 4],
   BufferL -> 1.5, BufferB -> 3, Order -> Vertical,
   XPanelSizes -> {1, 1}, XGapSizes -> 0.25, YGapSizes -> 0.2],
  FigurePanel[{1, 2}], 
  RawGraphics[
   Plot[Sin[15 x yslice1], {x, -1, 1}, Axes -> False, Frame -> True]],
  FigurePanel[{2, 2}], 
  RawGraphics[
   Plot[Sin[15 x yslice2], {x, -1, 1}, Axes -> False, Frame -> True]],
  FigurePanel[{2, 1}, PanelAdjustments -> {{0, 0}, {0, +1.2}}],
  RawGraphics[
   DensityPlot[Sin[15 x y], {x, -1, 1}, {y, -1, 1}, 
    ColorFunction -> "PlumColors", AspectRatio -> 2],
   Graphics[{Dashed, Thick, White, 
     Line[{{-1, yslice1}, {1, yslice1}}], 
     Line[{{-1, yslice2}, {1, yslice2}}]}]]},
 PlotRange -> {{0, 1}, {0, 1}}, ImageSize -> 2*72*{5, 3}
 ]

阴谋

I know that Multipanel in LevelScheme can probably let you do what you want - but I don't have much experience with it and the examples in the docs are fairly sparse.
I've already pasted one of the examples into this SO answer, so have a look there and see what you think!


Here's my attempt with GraphicsGrid.
The thing that Multipanel lets you do but GraphicsGrid doesn't
is to let you use varying Column/Row sizes.
This means that I struggled to get the arrows drawn in programmatically, and resorted to hand drawing them using the "Drawing Tools" panel ( :D )

With[{yslice1 = .5, yslice2 = -.8},
 GraphicsGrid[
  {{DensityPlot[Sin[15 x y], {x, -1, 1}, {y, -1, 1}, 
     ColorFunction -> "PlumColors", AspectRatio -> 2,
     Epilog -> {Dashed, White, Line[{{-1, yslice1}, {1, yslice1}}], 
       Line[{{-1, yslice2}, {1, yslice2}}]}],
    Plot[Sin[15 x yslice1], {x, -1, 1}, Axes -> False, Frame -> True]},
   {SpanFromAbove,
    Plot[Sin[15 x yslice2], {x, -1, 1}, Axes -> False, 
     Frame -> True]}},
  Spacings -> {Scaled[0.2], Scaled[0.0]}]]

enter image description here


Edit:

Here's the same thing using LevelScheme, note that the frames line up.
It should be possible to add arrows - since LevelScheme has lots of new arrow directives - but I'll leave that as a homework problem!

<< "LevelScheme`"
{yslice1 = .5, yslice2 = -.8};
Figure[{
  SetOptions[Multipanel, 
   ShowTickLabels -> {True, False, False, True}, Background -> Wheat,
   PanelLetterFontSize -> 10, Margin -> {{40, 40}, {40, 0}}],
  Multipanel[{{0, 1}, {0, 1}}, {2, 2},
   XPlotRanges -> {-1, 1}, YPlotRanges -> {-1, 1},
   XFrameLabels -> textit["x"], YFrameLabels -> textit["y"],
   TickFontSize -> 10, XFrameTicks -> LinTicks[-1, 1, .5, 4], 
   YFrameTicks -> LinTicks[-1, 1, .5, 4],
   BufferL -> 1.5, BufferB -> 3, Order -> Vertical,
   XPanelSizes -> {1, 1}, XGapSizes -> 0.25, YGapSizes -> 0.2],
  FigurePanel[{1, 2}], 
  RawGraphics[
   Plot[Sin[15 x yslice1], {x, -1, 1}, Axes -> False, Frame -> True]],
  FigurePanel[{2, 2}], 
  RawGraphics[
   Plot[Sin[15 x yslice2], {x, -1, 1}, Axes -> False, Frame -> True]],
  FigurePanel[{2, 1}, PanelAdjustments -> {{0, 0}, {0, +1.2}}],
  RawGraphics[
   DensityPlot[Sin[15 x y], {x, -1, 1}, {y, -1, 1}, 
    ColorFunction -> "PlumColors", AspectRatio -> 2],
   Graphics[{Dashed, Thick, White, 
     Line[{{-1, yslice1}, {1, yslice1}}], 
     Line[{{-1, yslice2}, {1, yslice2}}]}]]},
 PlotRange -> {{0, 1}, {0, 1}}, ImageSize -> 2*72*{5, 3}
 ]

scheming

孤单情人 2024-11-02 15:46:35

关于 GraphicsGrid 的OP评论,您可以使用 FullGraphics@GraphicsGrid@{...} 来获取单个图形对象。这对于获得 PDF 格式的副本也能正常工作是必要的。

Re the OPs comment about GraphicsGrid, you can use FullGraphics@GraphicsGrid@{...} to get a single graphics object out. This is necessary to get copy as PDF to work also.

染年凉城似染瑾 2024-11-02 15:46:35

这是使西蒙的解决方案动态化的第一步。箭头针对该特定图像进行了硬编码。稍后我将尝试更普遍地实施它们。

dp1 = DensityPlot[Sin[15 x y], {x, -1, 1}, {y, -1, 1}, 
   ColorFunction -> "PlumColors", AspectRatio -> 2, PlotPoints -> 30];
Manipulate[
 Show[
  GraphicsGrid[{{dp1 ~Append~
        (Epilog -> {Dashed, White, 
         Line[{{-1, yslice1}, {1, yslice1}}], 
         Line[{{-1, yslice2}, {1, yslice2}}]}), 
     Plot[Sin[15 x yslice1], {x, -1, 1}, Axes -> False, 
      Frame -> True]}, {SpanFromAbove, 
     Plot[Sin[15 x yslice2], {x, -1, 1}, Axes -> False, 
      Frame -> True]}}, Spacings -> {Scaled[0.2], Scaled[0.0]}],
  Graphics[{Red, {Arrowheads[Large],
     Arrow[{{380, Rescale[yslice1, {-1, 1}, {-646, -46}]}, {440, -170}}], 
     Arrow[{{380, Rescale[yslice2, {-1, 1}, {-646, -46}]}, {440, -530}}]
     }}],
  ImageSize -> 600
 ],
 {{yslice1, 0.5, "Slice 1"}, -1, 1},
 {{yslice2, -0.8, "Slice 2"}, -1, 1}
]

这是一种稍微不同的方法,它将箭头放在 Epilog 内,将它们的位置链接到左侧图,也许更容易使用。

dp1 = DensityPlot[Sin[15 x y], {x, -1, 1}, {y, -1, 1}, 
   ColorFunction -> "PlumColors", AspectRatio -> 2, PlotPoints -> 30, 
   PlotRangeClipping -> False, 
   ImagePadding -> {{Automatic, 100}, {Automatic, Automatic}}];
Manipulate[
 Show[
  GraphicsGrid[{{dp1~
      Append~(Epilog -> {{Dashed, White, 
          Line[{{-1, yslice1}, {1, yslice1}}], 
          Line[{{-1, yslice2}, {1, yslice2}}]}, {Red, 
          Arrowheads[Large],
          Arrow[{{1, yslice1}, {1.7, 0.88}}], 
          Arrow[{{1, yslice2}, {1.7, -0.9}}]
          }}), 
     Plot[Sin[15 x yslice1], {x, -1, 1}, Axes -> False, 
      Frame -> True]}, {SpanFromAbove, 
     Plot[Sin[15 x yslice2], {x, -1, 1}, Axes -> False, 
      Frame -> True]}}, Spacings -> {Scaled[-0.2], Scaled[0.0]}],
  ImageSize -> 600
  ],
 {{yslice1, 0.5, "Slice 1"}, -1, 1},
 {{yslice2, -0.8, "Slice 2"}, -1, 1}
 ]

Here is a first pass at making Simon's solution dynamic. The arrows are hard coded for this particular image. Later I shall try to implement them more generally.

dp1 = DensityPlot[Sin[15 x y], {x, -1, 1}, {y, -1, 1}, 
   ColorFunction -> "PlumColors", AspectRatio -> 2, PlotPoints -> 30];
Manipulate[
 Show[
  GraphicsGrid[{{dp1 ~Append~
        (Epilog -> {Dashed, White, 
         Line[{{-1, yslice1}, {1, yslice1}}], 
         Line[{{-1, yslice2}, {1, yslice2}}]}), 
     Plot[Sin[15 x yslice1], {x, -1, 1}, Axes -> False, 
      Frame -> True]}, {SpanFromAbove, 
     Plot[Sin[15 x yslice2], {x, -1, 1}, Axes -> False, 
      Frame -> True]}}, Spacings -> {Scaled[0.2], Scaled[0.0]}],
  Graphics[{Red, {Arrowheads[Large],
     Arrow[{{380, Rescale[yslice1, {-1, 1}, {-646, -46}]}, {440, -170}}], 
     Arrow[{{380, Rescale[yslice2, {-1, 1}, {-646, -46}]}, {440, -530}}]
     }}],
  ImageSize -> 600
 ],
 {{yslice1, 0.5, "Slice 1"}, -1, 1},
 {{yslice2, -0.8, "Slice 2"}, -1, 1}
]

Here is a slightly different method that puts the arrows inside Epilog, which links their position to the left plot, perhaps easier to use.

dp1 = DensityPlot[Sin[15 x y], {x, -1, 1}, {y, -1, 1}, 
   ColorFunction -> "PlumColors", AspectRatio -> 2, PlotPoints -> 30, 
   PlotRangeClipping -> False, 
   ImagePadding -> {{Automatic, 100}, {Automatic, Automatic}}];
Manipulate[
 Show[
  GraphicsGrid[{{dp1~
      Append~(Epilog -> {{Dashed, White, 
          Line[{{-1, yslice1}, {1, yslice1}}], 
          Line[{{-1, yslice2}, {1, yslice2}}]}, {Red, 
          Arrowheads[Large],
          Arrow[{{1, yslice1}, {1.7, 0.88}}], 
          Arrow[{{1, yslice2}, {1.7, -0.9}}]
          }}), 
     Plot[Sin[15 x yslice1], {x, -1, 1}, Axes -> False, 
      Frame -> True]}, {SpanFromAbove, 
     Plot[Sin[15 x yslice2], {x, -1, 1}, Axes -> False, 
      Frame -> True]}}, Spacings -> {Scaled[-0.2], Scaled[0.0]}],
  ImageSize -> 600
  ],
 {{yslice1, 0.5, "Slice 1"}, -1, 1},
 {{yslice2, -0.8, "Slice 2"}, -1, 1}
 ]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文