3
$\begingroup$

For plots like the one shown below, what is the syntax for adding filling between particular lines and the axis, but only in the negative region:

enter image description here

$\endgroup$
3
$\begingroup$

Here's one way:

Plot[{(x - 1)^2 - 1/2, 0}, {x, 0, 3}, PlotStyle -> {Blue, None}, 
 Filling -> {2 -> {{1}, {None, LightGray}}}]

Plot filled only below axis

$\endgroup$
3
$\begingroup$

Try

Plot[{Cos[x], Sin[x] + 1/2}, {x, 0, 4 Pi},  
 Filling -> {2 -> {0, {Automatic, None}}}]

enter image description here

Alternatively,

Plot[{Cos[x], Sin[x] + 1/2}, {x, 0, 4 Pi}, 
 Filling -> {2 -> {Axis, {Automatic, None}}}]
same picture

You can also use Filling + FillingStyle

Plot[{Cos[x], Sin[x] + 1/2}, {x, 0, 4 Pi},  
  Filling -> {2 -> 0},
  FillingStyle -> {Opacity[.3, Red], None}]

enter image description here

Note: For some reason, FillingStyle -> {Automatic, None} does not work.

$\endgroup$

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.