Message Boards Message Boards

Specify a color in a contour plot according to density?

GROUPS:

The following code allows one to manipulate the parameters and see the corresponding contours for a bivariate normal. What I would like to do is make the background white after the density is below a value say .02. Using the following code creates a dark blue background. I was wondering if is blue because the density is less a particular value but am not sure. Is this possible to specify a density value, below which you can specify a color? I played around with ContourShading but with no success. Here is my code:

Manipulate[
 ContourPlot[
  PDF[BinormalDistribution[{Subscript[\[Mu], 1], Subscript[\[Mu], 
     2]}, {Subscript[\[Sigma], 1], Subscript[\[Sigma], 
     2]}, \[Rho]], {x, y}], {x, -3, 3}, {y, -3, 3}, 
  ContourLabels -> True, PlotRange -> All, 
  PlotPoints -> 40], {Subscript[\[Mu], 1], -2, 2}, {Subscript[\[Mu], 
  2], -2, 2}, {Subscript[\[Sigma], 1], 1, 3}, {Subscript[\[Sigma], 2],
   1, 3}, {\[Rho], -0.9, 0.9}]
POSTED BY: Terry Ackerman
Answer
8 months ago

You may play around with PlotLegends and ColorFunction. For example

Manipulate[
 ContourPlot[
  PDF[BinormalDistribution[{Subscript[\[Mu], 1], 
     Subscript[\[Mu], 2]}, {Subscript[\[Sigma], 1], 
     Subscript[\[Sigma], 2]}, \[Rho]], {x, y}], {x, -3, 3}, {y, -3, 
   3}, ContourLabels -> True, PlotRange -> All, PlotPoints -> 40, 
  PlotLegends -> Automatic, 
  ColorFunction -> (ColorData["GreenBrownTerrain"][
      1 - #] &)], {Subscript[\[Mu], 1], -2, 
  2}, {Subscript[\[Mu], 2], -2, 2}, {Subscript[\[Sigma], 1], 1, 
  3}, {Subscript[\[Sigma], 2], 1, 3}, {\[Rho], -0.9, 0.9}]
POSTED BY: Gianluca Gorni
Answer
8 months ago

Gianluca, Your suggestion is very helpful and what I was looking for. I have a couple of follow-up questions. Did you create the GreenBrownTerrain? Could you send me where to look to create other color profiles? Thanks for all your help! Terry

POSTED BY: Terry Ackerman
Answer
8 months ago

Terry,

You can find the gradients listed here: http://reference.wolfram.com/language/guide/ColorSchemes.html

POSTED BY: Neil Singer
Answer
8 months ago

It's one of the thousands of features of Mathematica. Look up ColorData, ColorSchemes in the documentation. There is also a ColorSchemes palette.

POSTED BY: Gianluca Gorni
Answer
8 months ago

Group Abstract Group Abstract