Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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

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

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

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.