Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overlay two ReliefPlots, or other graphics

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!

like image 617
cormullion Avatar asked Nov 09 '11 15:11

cormullion


People also ask

How do I overlay multiple plots in R?

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.

How do you overlay plots in SAS?

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.

What are overlay graphs?

Overlay plots are different plots (like vectors and contours) that are drawn on top of each other, and possibly on top of a map.


3 Answers

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}].

like image 65
abcd Avatar answered Nov 11 '22 05:11

abcd


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

like image 28
Brett Champion Avatar answered Nov 11 '22 05:11

Brett Champion


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

like image 10
Szabolcs Avatar answered Nov 11 '22 05:11

Szabolcs