1
$\begingroup$

I'd like to apply a ColorData to this plot:

\[ScriptCapitalM] = 
  MixtureDistribution[{0.55, 0.35, 
    0.1}, {DiscreteUniformDistribution[{0, 0}], 
    NormalDistribution[0.25, .05], 
    DiscreteUniformDistribution[{1, 1}]}];

Plot[{CDF[\[ScriptCapitalM]]@x}, {x, -.001, 1.001}, Filling -> Axis, 
 PlotRange -> All, PlotStyle -> {{Blue, Thick}}, 
 Frame -> {{True, False}, {True, False}}, 
 FrameLabel -> {Style["Costs", Bold, 40], 
   Style["CDF(Costs)", Bold, 40]}, 
 FrameStyle -> Directive[Thick, Black, 30], GridLines -> Automatic, 
 GridLinesStyle -> Directive[Gray, Dashed], 
 ColorFunction -> (ColorData["HTML", "MidnightBlue"])]

that starts from green (left) to red (right). I've checked the available schemes but apparently none matches my objective. Any ideas how to this? Thanks!

$\endgroup$

1 Answer 1

4
$\begingroup$

You can define the ColorFunction to be a function of the values in the plot. If you allow this to be an RGBColor function you can let it take in the value of the x coordinate and define the colour scheme as you need:

\[ScriptCapitalM] = 
MixtureDistribution[{0.55, 0.35, 
0.1}, {DiscreteUniformDistribution[{0, 0}], 
NormalDistribution[0.25, .05], 
DiscreteUniformDistribution[{1, 1}]}];

Plot[{CDF[\[ScriptCapitalM]]@x}, {x, -.001, 1.001}, Filling -> Axis, 
PlotRange -> All, PlotStyle -> {{Blue, Thick}}, 
Frame -> {{True, False}, {True, False}}, 
FrameLabel -> {Style["Costs", Bold, 40], 
Style["CDF(Costs)", Bold, 40]}, 
FrameStyle -> Directive[Thick, Black, 30], GridLines -> Automatic, 
GridLinesStyle -> Directive[Gray, Dashed], 
ColorFunction -> (Function[{x}, RGBColor[x, (1 - x), 0]])]

from green to red

$\endgroup$
5
  • $\begingroup$ I'd like the red to dominate. I used: ColorFunction -> (Function[{x}, RGBColor[x, 0.25*(1 - x), 0]]) but this makes the colors really dark. Can you please tell me how to make them more clear? Thanks $\endgroup$
    – jpcgandre
    May 30, 2013 at 1:54
  • 1
    $\begingroup$ The fourth slot in RGBColor allows you to specify the Opacity, this may help to lighten it a little. You can also user the Lighter function around the RGBColor function $\endgroup$ May 30, 2013 at 2:00
  • 1
    $\begingroup$ You could also use: RGBColor[x, (1 - Sqrt[x]), 0] or some other power of x. $\endgroup$ May 30, 2013 at 2:02
  • $\begingroup$ Just a final question: If I wanted to catch all the intermediate colors, i.e orange, yellow, etc... How can I do it? $\endgroup$
    – jpcgandre
    May 30, 2013 at 2:18
  • $\begingroup$ The it's probably easiest to use ColorFunction -> (Function[{x}, Hue[x]]) or some function within the Hue command. $\endgroup$ May 30, 2013 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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