8
$\begingroup$

I have two ArrayPlots, and I want to overlap them as it is done here.

For clarity, suppose

Array1 = RandomReal[{0, 1}, {3, 2}]; 
Array2 = RandomReal[{0, 1}, {3, 2}];

and the first ArrayPlot uses ColorFunction -> (Blend[{White,Yellow},#]&), and the second uses ColorFunction -> (Blend[{White,Blue},#]&).

I'd like to combine them in such a way I end up with an ArrayPlot with White, Yellow, Blue and Green shades.

Thanks for your attention.

$\endgroup$
3
  • $\begingroup$ Won't the top plot completely block the bottom one? Do you mean set an opacity for top level see-through? - judging by your green color in question. $\endgroup$ Commented Jun 26, 2012 at 3:51
  • 2
    $\begingroup$ There is one big difference between the linked example of overlapping histograms and this question of overlapping array plots: The dimensions of Array1 and Array1 are identical, so there is never any partial overlap. For that reason, I can't see why you don't just create a third new array (e.g. the sum) from the two given ones and plot that with the desired color scheme. It would be a much cleaner solution, I think. $\endgroup$
    – Jens
    Commented Jun 26, 2012 at 6:39
  • $\begingroup$ I'm not sure about this, as I must be able to see from which array are some points that can have roughly the same values, i.e. A1[[1,1]] = 0.5, A1[[1,2]] = 0, A2[[1,1]] = 0, A2[[1,2]] = 0.5, the sum would be the same, but I'd like the point (1,1) to be a shade of Yellow, while the point (1,2) to be a shade of Blue. $\endgroup$
    – Pragabhava
    Commented Jun 26, 2012 at 16:02

3 Answers 3

8
$\begingroup$

How about this?

ImageMultiply @@
 Table[
  ArrayPlot[RandomReal[{0, 1}, {5, 5}], ColorFunction -> (Blend[{White, color}, #] &)],
  {color, {Yellow, RGBColor[0, 0.6, 1]}}
 ]

Mathematica graphics

The same operation can be done on the Raster data to preserve full scalability:

gr =
  Table[
    ArrayPlot[RandomReal[{0, 1}, {5, 5}], ColorFunction -> (Blend[{White, color}, #] &)],
    {color, {Yellow, RGBColor[0, 0.6, 1]}}
  ]

Graphics[
  Raster[gr[[1, 1, 1]]*gr[[2, 1, 1]]],
  Options[gr[[1]]]
]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ I like this a lot, as it preserves the intensity of the colors. Thanks a lot Mr.Wizard $\endgroup$
    – Pragabhava
    Commented Jun 26, 2012 at 16:34
  • $\begingroup$ @Manuel you're welcome; I like it for the same reason. $\endgroup$
    – Mr.Wizard
    Commented Jun 27, 2012 at 2:10
7
$\begingroup$

Is it something like this?

p1 = ArrayPlot[RandomReal[{0, 1}, {3, 2}],ColorFunction -> (Blend[{White, Yellow}, #] &)];
p2 = ArrayPlot[RandomReal[{0, 1}, {3, 2}],ColorFunction -> (Blend[{White, Blue}, #] &)];
Overlay[{p1, SetAlphaChannel[p2, .5]}]

enter image description here

$\endgroup$
3
  • $\begingroup$ No Overlay nor SetAlphaChannel function are on my version of Mathematica (v7.0.1/Linux x64). I suppose working with ImageCompose (wich I found thanks to your answer), would somehow be the same. $\endgroup$
    – Pragabhava
    Commented Jun 26, 2012 at 16:27
  • $\begingroup$ @Manuel I am also on version 7. You could use something like this to get a result similar to Overlay: Show[p1, Graphics[{Opacity[0.5], p2[[1]]}]] $\endgroup$
    – Mr.Wizard
    Commented Jun 27, 2012 at 2:08
  • $\begingroup$ @Mr.Wizard Tanks again. This tip will be helpful in other situtions. $\endgroup$
    – Pragabhava
    Commented Jun 27, 2012 at 17:08
5
$\begingroup$

You can use ColorFunction with a fourth argument in RGBColor. This argument sets the transparency of the color. For example, this blends a transparent Red (ie white) into full on Red:

transRed = (Blend[{RGBColor[1, 0, 0, 0], RGBColor[1, 0, 0, 1]}, #] &);

Similarly,

transGreen = (Blend[{RGBColor[0, 1, 0, 0], RGBColor[0, 1 , 0, 1]}, #] &);

Then, you can use these as the ColorFunction in an ArrayPlot (or DensityPlot, etc). For example:

redplot = ArrayPlot[RandomReal[{0, 1}, {20, 20}], ColorFunction -> transRed]
greenplot = ArrayPlot[RandomReal[{0, 1}, {20, 20}], ColorFunction -> transGreen]

Mathematica graphics Mathematica graphics

If you want to overlay them, you can do it with Show:

Show[redplot,greenplot]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Why not show this with yellow and blue as the OP requested? Nevertheless +1. $\endgroup$
    – Mr.Wizard
    Commented Oct 4, 2012 at 18:47
  • $\begingroup$ @Mr.Wizard Answered on now-closed other question: mathematica.stackexchange.com/questions/11565/… and am too busy to re-write ATM. $\endgroup$
    – Eli Lansey
    Commented Oct 4, 2012 at 20:39
  • $\begingroup$ This is a great solution also. Thanks! $\endgroup$
    – Pragabhava
    Commented Oct 5, 2012 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.