2
$\begingroup$

How can I fill the area between the curves? I cant seem to fill all three of them...

plot output - no code

$\endgroup$
  • 1
    $\begingroup$ Please share code (instead of an image) and the definitions for your functions next time. It really helps in quickly trying out your examples and posting solutions. $\endgroup$ – halirutan May 5 at 18:13
2
$\begingroup$

How about creating the filling and the plot separately and combining them later?

yf[x_] := -x^2 + 2;
yg[x_] := -x;
yh[x_] := x;
plot = Plot[{yf[x], yg[x], yh[x]}, {x, -2, 2}];
fill = RegionPlot[yf[x] > y && (yg[x] < y || yh[x] < y), {x, -2, 2}, {y, -2, 2},
  PlotPoints -> 50,
  MaxRecursion -> 3];
Show[fill, plot]

Mathematica graphics

| improve this answer | |
$\endgroup$
2
$\begingroup$

If you just want some kind of filling, you can just add from curve 1 to 3 as well:

Plot[{
  -x^2 + 2,
  -x,
  x
  },
 {x, -2, 2},
 Filling -> {1 -> {2}, 1 -> {3}}
]

Plot with filling.

The area above the yellow and green lines is darker because it's effective being filled twice. If you want the shading to be uniform, you can either use halirutan's answer, or you can specify a colour with no opacity as the filling:

Plot[{
  -x^2 + 2,
  -x,
  x
  },
 {x, -2, 2},
 Filling -> {1 -> {{2}, LightBlue}, 1 -> {{3}, LightBlue}}
]

Plot with uniform filling.

| improve this answer | |
$\endgroup$
0
$\begingroup$
yf[x_] := -x^2 + 2;
yg[x_] := -x;
yh[x_] := x;

Plot[{yf[x], yg[x], yh[x], Min[yg[x], yh[x]]}, {x, -2, 2}, 
 PlotStyle -> {Automatic, Automatic, Automatic, None}, 
 Filling -> {1 -> {4}}]

enter image description here

You can also use ParametricPlot as follows:

ParametricPlot[{{x, v Min[yg[x], yh[x]] + (1 - v) yf[x]}, {x, yg[x]}, {x, yh[x]}}, 
  {x, -2, 2}, {v, 0, 1}, 
 Axes -> False, Exclusions -> None, BaseStyle -> Thick]

enter image description here

| improve this answer | |
$\endgroup$

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.