# Filling a plotted line both below and above the line

I'm relatively new to Mathematica. I tried looking for a solution online but couldn't find anything. I want to fill a plotted line both above the line (one color) and below (another color). For example, the line might be given by y = 1 - x over domain (0, 1) and with range (0, 1).

Any suggestions?

-

This works:

Plot[1 - x, {x, 0, 1},
Filling -> { 1 -> Top, 1 -> {Bottom, {Green, Blue}}}
]


but I think there may be a neater solution.

-
Great- this works perfectly. Thanks to Jonie and Mike! – Sam Jul 26 '13 at 1:33

For an above and below type fill, as an alternative to @Jonie you can use FillingStyle:

FillingStyle->{Subscript[g, -],Subscript[g, +]} specifies that the filling should be done with Subscript[g, -] when a point, curve or surface lies below the object being filled to, and with Subscript[g, +] when it lies above.

Plot[1 - x, {x, 0, 1}, Filling -> {1 -> Top, 1 -> Bottom},
FillingStyle -> {Green, Blue}]


Edit

After re-reading I am not entirely sure what you are looking for. If you want the fill constrained in the x direction as well then:

Plot[{If[0 <= x <= 1, 1 - x], 1 - x}, {x, 0, 2},
Filling -> {1 -> Top, 1 -> Axis}, FillingStyle -> {Green, Blue}]


-