如何叠加两个浮雕图或其他图形
如果图形是由 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您必须向
ColorFunction
发出不透明度指令,如下所示:此处输入图像描述">
You'll have to issue the opacity directive to
ColorFunction
like so:In general, in all
*Plot*
functions, you control opacity with eitherPlotStyle
orColorFunction
, as the case may be. If this were just aGraphics
primitive, you'd probably do something likeGraphics[{Opacity[0.5], object}]
.由于
ReliefPlot
没有PlotStyle
选项,因此您可以使用BaseStyle -> Opacity[0.5]
为图形引入透明度。Since
ReliefPlot
doesn't have aPlotStyle
option, you can useBaseStyle -> Opacity[0.5]
to introduce transparency into the graphics.另一种方法是使用
Image
和ReliefImage
函数,然后使用ImageCompose
将生成的图像组合在一起:自从
ReliefPlot
本质上还以与Graphics
兼容的格式返回像素数据,也许Image
更适合您。ReliefImage
的默认颜色函数有所不同:您可以使用ColorFunction -> “LakeColors”
切换到ReliefPlot
的颜色。最初我有一个函数从
ReliefPlot
中提取光栅数据,但后来Brett Champion在下面的评论中指出了RasterImage
An alternative is to work with
Image
s and theReliefImage
function, and then compose the resulting images together usingImageCompose
:Since
ReliefPlot
also essentially returns pixel data in aGraphics
-compatible format, perhapsImage
s will suit you better.The default colour function of
ReliefImage
is different: you can useColorFunction -> "LakeColors"
to switch toReliefPlot
's one.Originally I had a function here to extract the raster data from
ReliefPlot
, but then Brett Champion pointed toRasterImage
in the comment below使用透明度的答案将以非常通用的方式工作,但在这个组合两个 ReliefPlot[] 的特定示例中,您可能需要考虑绘制两者的总和:
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: