Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

This works:

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

but I think there may be a neater solution.

share|improve this answer
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}]

enter image description here


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

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.