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 am using ParametricPlot to get an X vs Y plot. I want to shade the area enclosed by the curve falling in the region where Y<0.

For example, how to shade the area enclosed by the Sin curve where Sin[x]<0.

ParametricPlot[{x, Sin[x]}, {x, 0, xm}]
share|improve this question
If you're just plotting $y=f(x)$, it's simpler to use Plot[] with its Filling option... –  J. M. Aug 28 '12 at 5:25

3 Answers 3

 ParametricPlot[{ u, If[Sin[u] < 0, v, 1] Sin[u]},
   {u, -2 Pi, 2 Pi}, {v, 0, 1},
   AspectRatio -> 1, Mesh -> False,
   PlotStyle -> Directive[Red, Opacity[.8]]]

enter image description here

ParametricPlot[{ u, If[Sin[u] < 0, v, 1] Sin[u]},
 {u, -2 Pi, 2 Pi}, {v, 0, 1},
 Mesh -> False, AspectRatio -> 1, 
 ColorFunction -> Function[{x, y, u, v}, Hue[v]], 
 PlotPoints -> 100]

enter image description here

Update: Few alternatives that use {u, v Sin[u]} as the first argument of ParametricPlot:

Using ColorFunction:

ParametricPlot[{ u, v Sin[u]}, {u, -2 Pi, 2 Pi}, {v, 0, 1},
AspectRatio -> 1, Mesh -> False,
ColorFunction -> (If[Sin[#1] > 0, White, Red] &),
ColorFunctionScaling -> False,
PlotPoints -> 100]

Using Mesh, MeshFunctions and MeshStyle:

ParametricPlot[{u, v Sin[u]}, {u, -2 Pi, 2 Pi}, {v, 0, 1}, 
   AspectRatio -> 1,
   Mesh -> {{0.}},
   MeshFunctions -> {Function[{x, y, u, v}, y]},
   MeshShading -> {Red, White},
   PlotPoints -> 100]
share|improve this answer

Evaluation is faster than Verde's solution plus this little deviation close to the intersection is gone: Make a second plot of y Min[Sin[x],0.0] with y as an additional variable, so you can use the mesh to fill the area.

ParametricPlot[{{x, Sin[x]}, {x,y Min[Sin[x],0.0]}},
                 {x, 0, 2 Pi }, {y, 0, 1}, PlotRange -> All, AspectRatio -> 1, Mesh -> False]

Mathematica graphics

But it does not work perfectly, e.g. for a filling sin(x)<0.1.

share|improve this answer
Sadly I don't have enough reputation to post an image. –  jens_bo Aug 28 '12 at 6:06
I did it for you ... now you have some rep –  belisarius Aug 28 '12 at 6:08
Hi! welcome to Mathematica.SE! Please consider registering your account so that any upvotes you get on this answer are added to those you might get on future questions and answers. That way, over time you will be able to do more on the site (post graphics, edit things, etc). –  belisarius Aug 28 '12 at 6:11
Thanks a lot. I will try to collect some more points now :) –  jens_bo Aug 28 '12 at 8:08

You could do:

ParametricPlot[{{x, Sin[x]}, {x, y}}, {x, 0, 2 Pi}, {y, 0, Min[0, Sin@x]}, 
               Mesh -> None, PlotPoints -> 50, PlotRange -> {{0, 2 Pi}}]

Mathematica graphics


Using Plot[] is much easier

Plot[Sin@x, {x, 0, 2 Pi}, Filling -> {1 -> {Axis, {Yellow, None}}}]

Mathematica graphics

share|improve this answer
As always, credit to Heike for her torn[] magic, and to Szabolcs for his super-hyper image uploader palette –  belisarius Aug 28 '12 at 6:18

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.