9

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}}]

enter image description here

But I want something like this:

enter image description here

rm -rf
  • 88,781
  • 21
  • 293
  • 472
Alexis
  • 91
  • 1
  • 1
  • 2
  • 3
    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 '13 at 19:26
  • @rm-rf I closed this question because as it has been interpreted it is a duplicate, and I wish to respect the older, original question from a contributing member. However, that makes the answers here somewhat harder to find. Do you think this might be a case where a merge is appropriate? I believe the original can be modified so that all the answers make sense. – Mr.Wizard Jan 10 '14 at 10:28
  • @Mr.Wizard Why does it make this harder to find? Duplicates show up exactly as any other post and are just as searchable/rep-earnable. It's only the "answerless duplicates" that are automatically redirected. But I agree that a merge might not be all that bad (esp. since only belisarius has an answer there), and Anon has an apparently general version of a shading function... – rm -rf Jan 10 '14 at 16:10
  • @rm-rf I meant somewhat harder to find than if the close went the other way. Since you agree this is a good candidate for a merge, e.g. there is no Accepted answer here, I shall do that tomorrow unless you do it first. – Mr.Wizard Jan 10 '14 at 16:50

4 Answers4

14

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

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

Mathematica graphics

bobthechemist
  • 19,693
  • 4
  • 52
  • 138
4

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]]

enter image description here

C. E.
  • 70,533
  • 6
  • 140
  • 264
3

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}}]
Hector
  • 6,428
  • 15
  • 34
3
Plot[{x + 7, 9 - x^2}, {x, 0, 1.5}, 
 Filling -> {1 -> {{2}, {{Opacity[0.2], Hue[0.67, 0.6, 0.6]}, None}}}]

enter image description here

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

ybeltukov
  • 43,673
  • 5
  • 108
  • 212