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!
To draw multiple plots in the R Language, we draw a basic plot and add an overlay line plot or scatter plot by using the lines() and the points() function. This line and scatter plot overlay can be drawn on top of any layer in the R Language.
The OVERLAY option in the PLOT statement determines that both plot lines appear on the same graph. The other PLOT options scale the vertical axis, add a reference line to the plot, and specify the number of minor tick marks on the axes. The SYMBOL, AXIS, and LEGEND statements modify the plot symbols, axes, and legend.
Overlay plots are different plots (like vectors and contours) that are drawn on top of each other, and possibly on top of a map.
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]
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}]
.
Since ReliefPlot
doesn't have a PlotStyle
option, you can use BaseStyle -> Opacity[0.5]
to introduce transparency into the graphics.
An alternative is to work with Image
s 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}
]
Since ReliefPlot
also essentially returns pixel data in a Graphics
-compatible format, perhaps Image
s 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With