如何叠加两个浮雕图或其他图形

发布于 2024-12-14 12:25:56 字数 647 浏览 1 评论 0原文

如果图形是由 ReliefPlot 或 DensityPlot 等函数生成并使用不透明度控制外观,是否可以在 Mathematica 中叠加两个或多个图形?

例如:

a = ReliefPlot[
        Table[i + Sin[i^2 + j^2], {i, -4, 4, .03}, {j, -4, 4, .03}], ImageSize -> 100]
b = ReliefPlot[
        Table[i + Sin[i^3 + j^3], {i, -4, 4, .03}, {j, -4, 4, .03}], ImageSize -> 100]
Show[a,b]

将两者结合起来,但我无法弄清楚如何在此处的任何位置插入 Opacity 命令,以便两者都可见的。文档指出这些函数接受与 Graphics 相同的选项(“ReliefPlot 具有与 Graphics 相同的选项,但有以下添加和更改:”),但我不明白如何控制图形......(而且我可能也对图形选项和指令之间的差异感到困惑。)

启蒙 - 和更少的不透明度 - 非常欢迎!

编辑:哇,你们比我的 Mathematica 版本快 - 谢谢!

Is it possible to overlay two or more graphics in Mathematica, if the graphics are generated by functions such as ReliefPlot or DensityPlot, using Opacity to control the appearance?

For example:

a = ReliefPlot[
        Table[i + Sin[i^2 + j^2], {i, -4, 4, .03}, {j, -4, 4, .03}], ImageSize -> 100]
b = ReliefPlot[
        Table[i + Sin[i^3 + j^3], {i, -4, 4, .03}, {j, -4, 4, .03}], ImageSize -> 100]
Show[a,b]

combines the two, but I can't work out how to insert an Opacity command anywhere here such that both are visible. The documentation states that these functions accept the same options as Graphics ("ReliefPlot has the same options as Graphics, with the following additions and changes:"), but I don't understand how to control the graphics... (And I may be confused about the difference between graphics options and directives, as well.)

Enlightenment - and less opacity - very welcome!

Edit: Wow, you guys are quicker than my version of Mathematica - thanks!

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

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

发布评论

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

评论(5

三生路 2024-12-21 12:25:56

您必须向 ColorFunction 发出不透明度指令,如下所示:

a = ReliefPlot[
  Table[i + Sin[i^2 + j^2], {i, -4, 4, .03}, {j, -4, 4, .03}], 
  ImageSize -> 100]
b = ReliefPlot[
  Table[i + Sin[i^3 + j^3], {i, -4, 4, .03}, {j, -4, 4, .03}], 
  ImageSize -> 100, 
  ColorFunction -> (Directive[Opacity[0.5], 
      ColorData["Rainbow"][#]] &)]
Show[a, b]

此处输入图像描述">

You'll have to issue the opacity directive to ColorFunction like so:

a = ReliefPlot[
  Table[i + Sin[i^2 + j^2], {i, -4, 4, .03}, {j, -4, 4, .03}], 
  ImageSize -> 100]
b = ReliefPlot[
  Table[i + Sin[i^3 + j^3], {i, -4, 4, .03}, {j, -4, 4, .03}], 
  ImageSize -> 100, 
  ColorFunction -> (Directive[Opacity[0.5], 
      ColorData["Rainbow"][#]] &)]
Show[a, b]

enter image description here

In general, in all *Plot* functions, you control opacity with either PlotStyle or ColorFunction, as the case may be. If this were just a Graphics primitive, you'd probably do something like Graphics[{Opacity[0.5], object}].

挥剑断情 2024-12-21 12:25:56

由于 ReliefPlot 没有 PlotStyle 选项,因此您可以使用 BaseStyle -> Opacity[0.5] 为图形引入透明度。

在此处输入图像描述

Since ReliefPlot doesn't have a PlotStyle option, you can use BaseStyle -> Opacity[0.5] to introduce transparency into the graphics.

enter image description here

时光磨忆 2024-12-21 12:25:56

另一种方法是使用 ImageReliefImage 函数,然后使用 ImageCompose 将生成的图像组合在一起:

ImageCompose[
 ReliefImage[Table[i + Sin[i^2 + j^2], {i, -4, 4, .03}, {j, -4, 4, .03}]],
 {ReliefImage[Table[i + Sin[i^3 + j^3], {i, -4, 4, .03}, {j, -4, 4, .03}]], 
  0.5}
 ]

自从ReliefPlot 本质上还以与 Graphics 兼容的格式返回像素数据,也许 Image 更适合您。

ReliefImage 的默认颜色函数有所不同:您可以使用 ColorFunction -> “LakeColors” 切换到 ReliefPlot 的颜色。

最初我有一个函数从ReliefPlot中提取光栅数据,但后来Brett Champion在下面的评论中指出了RasterImage

An alternative is to work with Images and the ReliefImage function, and then compose the resulting images together using ImageCompose:

ImageCompose[
 ReliefImage[Table[i + Sin[i^2 + j^2], {i, -4, 4, .03}, {j, -4, 4, .03}]],
 {ReliefImage[Table[i + Sin[i^3 + j^3], {i, -4, 4, .03}, {j, -4, 4, .03}]], 
  0.5}
 ]

enter image description here

Since ReliefPlot also essentially returns pixel data in a Graphics-compatible format, perhaps Images will suit you better.

The default colour function of ReliefImage is different: you can use ColorFunction -> "LakeColors" to switch to ReliefPlot's one.

Originally I had a function here to extract the raster data from ReliefPlot, but then Brett Champion pointed to RasterImage in the comment below

無心 2024-12-21 12:25:56

使用透明度的答案将以非常通用的方式工作,但在这个组合两个 ReliefPlot[] 的特定示例中,您可能需要考虑绘制两者的总和:

f[i_] := i + Sin[i^2 + j^2];
g[i_] := i + Sin[i^3 + j^3];
ReliefPlot[Table[f[i] + g[i], {i, -4, 4, .03}, {j, -4, 4, .03}], ImageSize -> 100]

The answers using transparency will work in a very general way, but in this particular example of combining two ReliefPlot[]s, you might want to consider plotting the sum of the two:

f[i_] := i + Sin[i^2 + j^2];
g[i_] := i + Sin[i^3 + j^3];
ReliefPlot[Table[f[i] + g[i], {i, -4, 4, .03}, {j, -4, 4, .03}], ImageSize -> 100]
最冷一天 2024-12-21 12:25:56
Show[a, {Opacity[0.5],#}& /@ b]
Show[a, {Opacity[0.5],#}& /@ b]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文