1
$\begingroup$

I would like to fill a region below a curve using shading that represents a function (i.e. not just be filled in one solid color). Here is a working example.

(a system of ODEs, parameters and their solver)

eX[X_, Y_] := \[Rho] X - \[Beta] X Y - \[Mu] X
eY[X_, Y_] := \[Beta] X Y - \[Mu] Y 
parms = {\[Beta] -> 0.002 , \[Rho] -> 0.27, \[Mu] -> 0.25  };

sys = {X'[t] == eX[X[t], Y[t]], Y'[t] == eY[X[t], Y[t]],
X[0] == 1000, Y[0] == 1};
tmax = 400;
sol = NDSolve[sys /. parms, {X, Y}, {t, 0, tmax}];

(interpolating functions)

Xfn = Flatten[{X} /. sol];
Yfn = Flatten[{Y} /. sol];

(plot - curve is a sum of the two functions)

RegionPlot[{y < Evaluate[Xfn[[1]][t] + Yfn[[1]][t]]}, {t, 0, 50}, 
{y, 0, 1200}, ColorFunction -> Function[{t, y}, t]]

I would like the shading under the curve to change as a function of this ratio:

Yfn/(Xfn+Yfn)

I'm assuming that this means changing "Function[{t,y},t]" in ColorFunction to include the function (above) of the ratio, probably in the place of the first t. However, I just can't figure it out. Thanks in advance.

image of curve

$\endgroup$
1
  • $\begingroup$ ColorFunction -> Function[{t, y}, Yfn[[1]][t]/(Xfn[[1]][t] + Yfn[[1]][t])] but that doesn't show much details (see also Plot[Yfn[[1]][t]/(Xfn[[1]][t] + Yfn[[1]][t]), {t, 0, 50}]). $\endgroup$
    – corey979
    Oct 26 '16 at 9:00
5
$\begingroup$

Using Blend. Apologies if I have misunderstood.

rp = RegionPlot[{y < Evaluate[Xfn[[1]][t] + Yfn[[1]][t]]}, {t, 0, 
    50}, {y, 0, 1200}, 
   ColorFunction -> 
    Function[{t, y}, 
     Blend[{Red, Green}, Yfn[[1]][t]/(Xfn[[1]][t] + Yfn[[1]][t])]], 
   ColorFunctionScaling -> False];
f = Plot[1000 Yfn[[1]][t]/(Xfn[[1]][t] + Yfn[[1]][t]) - 1200, {t, 0, 
    50}, ColorFunction -> 
    Function[{t, y}, 
     Blend[{Red, Green}, Yfn[[1]][t]/(Xfn[[1]][t] + Yfn[[1]][t])]], 
   ColorFunctionScaling -> False, Frame -> True];
Show[rp, f, PlotRange -> {-1200, 1200}, 
 FrameTicks -> {Automatic, Range[0, 1000, 500]}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Perfect! that worked wonderfully! Thanks. $\endgroup$
    – LiaChica
    Oct 26 '16 at 16:28

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.