4
$\begingroup$

I want to realize the domains in which $\sin x<0$ and $\sin x \geq 0$. I use this code

Plot[{Sin[x], If[Sin[x] < 0, 0], If[Sin[x] >= 0, 0]}, {x, 0, 10}, 
 PlotStyle -> {Automatic, 
   Directive[Yellow, Opacity[60], Thickness[.08]], 
   Directive[Red, Opacity[1], Thickness[.03]]}]

and I get enter image description here

In the plot, the yellow and red parts have some common areas which are not true! How can I modify it to have the exact result? I have to use a big thickness for them since I want them to be visible over a large number of $x$.

$\endgroup$
10
$\begingroup$

Add CapForm["Butt"] inside Directive:

Plot[{Sin[x], If[Sin[x] < 0, 0], If[Sin[x] >= 0, 0]}, {x, 0, 10}, 
 PlotStyle -> {Automatic, 
   Directive[Yellow, CapForm["Butt"], Opacity[1], Thickness[.08]], 
   Directive[Red, CapForm["Butt"], Opacity[1], Thickness[.03]]}]

enter image description here

$\endgroup$
2
  • $\begingroup$ I really appreciate your time and answers. $\endgroup$ – charmin Nov 3 '20 at 18:44
  • $\begingroup$ @charmin, my pleasure. Thank you for the accept. $\endgroup$ – kglr Nov 3 '20 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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