Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opacity control for overlaying plots

Given two vector plots and a contour plot like the following

as = VectorPlot[{Cos[y], Sin[x] }, {x, -3, 3}, {y, -3, 3},
                 VectorScale -> Automatic, VectorColorFunction -> "Rainbow"
     ];
bs = StreamPlot[{Cos[y], Sin[x] }, {x, -3, 3}, {y, -3, 3},
                 VectorScale -> Automatic, StreamColorFunction -> "Rainbow"
     ];
cs = ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3},
                 ColorFunction -> "BlueGreenYellow"
     ];
Show[cs, bs, as]

enter image description here

we can see basic superimposing job is well done by Show[]. But my question is how can I control the opacity of the background contour plot cs? Also, how can I insert "BlueGreenYellow" type color schemes in a color function like the following?

ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3},
            ColorFunction -> (Directive[Opacity[#],Blue] &)
];
like image 477
PlatoManiac Avatar asked Jul 04 '11 08:07

PlatoManiac


2 Answers

I do not believe that jmlopez' solution is correct, because the vectors and the frame are also partially transparent. I believe that it is better to insert an Opacity command into the Graphics object, which will preserve opaque vectors:

as = VectorPlot[{Cos[y], Sin[x]}, {x, -3, 3}, {y, -3, 3}, 
       VectorScale -> Automatic, VectorColorFunction -> "Rainbow"];
bs = StreamPlot[{Cos[y], Sin[x]}, {x, -3, 3}, {y, -3, 3}, 
       VectorScale -> Automatic, StreamColorFunction -> "Rainbow"];
cs = ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3}, 
       ColorFunction -> "BlueGreenYellow"];

cs2 = MapAt[{Opacity[0.5], #} &, cs, 1];

Show[cs2, bs, as]

enter image description here


The second question was never addressed. You can combine opacity and a color gradient like this:

ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3}, 
  ColorFunction -> ({Opacity[#], ColorData["BlueGreenYellow"][#]} &)
]

enter image description here

like image 169
Mr.Wizard Avatar answered Oct 13 '22 11:10

Mr.Wizard


You can try using BaseStyle as follows:

cs = ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3}, 
                 ColorFunction -> "BlueGreenYellow", 
                 BaseStyle -> Directive[Opacity[0.5]]
     ];

enter image description here

like image 21
jmlopez Avatar answered Oct 13 '22 09:10

jmlopez