# Using Filling went wrong

f[x_] = If[x >= 0 && x <= 2, {4 - x^2, 2 x - x^2}];

p1 = Plot[f[x], {x, -3, 3}, Frame -> True, GridLines -> Automatic,
PlotStyle -> Blue, ImageSize -> 550, Filling -> {1 -> {2, Orange}},
FillingStyle -> Directive[Opacity[0.1], Orange]];
p2 = Plot[{4 - x^2, 2 x - x^2}, {x, -3, 3}]; Show[{p1, p2},
PlotRange -> {-2, 5}]


Why do I get the area to the right colored?

• f is a vector-valued function, not the scalar function. Commented Mar 10, 2023 at 11:52

Even though you return a list in your f[x], Mathematica sees this as a single curve. You should explicitly provide two separate curves:

curves = {4 - x^2, 2 x - x^2};

p1 = Plot[curves, {x, -3, 3}];
p2 = Plot[curves, {x, 0, 2},
Filling -> {1 -> {{2}, Opacity[.2, Orange]}}];

Show[p1, p2, Frame -> True, GridLines -> Automatic]


You can use Region functionality as follows:

Clear["Global*"]
curves = {4 - x^2, 2 x - x^2};
p3 = Plot[curves, {x, -3, 3}
, Frame -> True
, PlotStyle -> Thick
, GridLines -> Automatic
, ImageSize -> 550
];
reg = ImplicitRegion[
y < First@curves && y >= Last@curves, {{x, 0, 2}, y}]
p4 = RegionPlot[reg
, PlotStyle -> Directive[Yellow, Opacity[0.4]]
, BoundaryStyle -> Directive[Red, Thick]
];

Show[p3, p4]
`