Plot Filling restricted to domain segment
One Plot
can do too:
Plot[{If[x < 1, 1/(x^2)], If[x > 1, 1/(x^2)]}, {x, 0, 4}
, AspectRatio -> 1
, Filling -> {2 -> {Axis, Red}}
, Epilog -> {Purple, Rectangle[]}
]
Show[Plot[1/(x^2), {x, 0, 4}, PlotStyle -> Blue, AspectRatio -> 1],
Plot[1, {x, 0, 1}, FillingStyle -> Purple, Filling -> Bottom,
PlotStyle -> Blue],
Plot[1/(x^2), {x, 1, 4}, PlotStyle -> Blue, Filling -> Axis,
FillingStyle -> Red, PlotRange -> {Full, {0, 1}}]]
Another variation, using ConditionalExpression
:
Plot[{
ConditionalExpression[x^-2, x <= 1],
ConditionalExpression[x^-2, x > 1],
ConditionalExpression[1, x <= 1]}
, {x, 0, 4}, PlotStyle -> Blue,
Filling -> {2 -> {Axis, Red}, 3 -> {Axis, Purple}}]