# Filling Between Curves

I want to fill in the region between the curves.

So far I have this:

Plot[{x + 7, 9 - x^2}, {x, 0, 1.5}, Filling -> {1 -> {2}}]


But I want something like this:

-
So what's the logic here? 1) Fill to the left of the point of intersection? 2) Fill when curve 2 is above curve 1? 3) Fill the first enclosure between the two curves? –  rm -rf Sep 27 at 19:26

Alternatively, you can use the +/- option of Filling

Plot[{x + 7, 9 - x^2}, {x, 0, 1.5}, Filling -> {1 -> {{2}, {LightBlue, White}}}]


-
I would use None not White. –  rcollyer Sep 27 at 19:34
@rcollyer While I'm changing the colors, do you know off hand what the default blue is? –  bobthechemist Sep 27 at 19:37
The simplest way to get that color is to run, ColorData[1][1]. Then fiddle with the Opacity until you're content. –  rcollyer Sep 27 at 19:38
@bobthechemist Your answer was a few seconds before. I was late while extracting the default color from Plot[...]//InputForm :) –  ybeltukov Sep 27 at 19:47
No need to extract any color... just use Automatic :) –  rm -rf Sep 27 at 19:50

Since Filling shades between two curves in the plot, add an extra curve that serves as the limit.

Plot[{Max[x + 7, 9 - x^2], x + 7, 9 - x^2}, {x, 0, 1.5}, Filling -> {1 -> {2}}]

-
Plot[{x + 7, 9 - x^2}, {x, 0, 1.5},
Filling -> {1 -> {{2}, {{Opacity[0.2], Hue[0.67, 0.6, 0.6]}, None}}}]


Update: you can use Automatic instead of {Opacity[0.2], Hue[0.67, 0.6, 0.6]}.

-

It's like rm-rf says in his comments, it's not really clear what the logic is. There are already plenty of ways to use Filling to produce the requested plot but here's a more general function to facilitate arbitrary logic:

shadeBoundedArea[plot_, region_] := Module[{rangex, rangey},
{rangex, rangey} = PlotRange /. AbsoluteOptions[plot];
Show[
plot,
RegionPlot[region, Evaluate@{x, Sequence @@ rangex},
Evaluate@{y, Sequence @@ rangey}]
]
]

Clear[x, y];

p = Plot[{f1[x], f2[x]}, {x, 0, 1.5}]

shadeBoundedArea[p, f1[x] < y < f2[x]]


-