3
$\begingroup$

How to fill the area between two curves, but without plotting those curves?

For example,

Plot[Sin[x], {x, 0, 2 Pi}, Filling -> {1 -> 0.5}]

gives a plot like this

enter image description here

(0.5 without any marked boundary = form required for a generalization)

but Plot[Sin[x], {x, 0, 2 Pi}, Filling -> {1 -> (Sin[x] - 0.5)}]

draws a plot without filling or even gives an error

$\endgroup$
  • 3
    $\begingroup$ PlotStyle -> None? $\endgroup$ – Kuba Dec 1 '17 at 12:58
  • $\begingroup$ wow, thank you @Kuba $\endgroup$ – Slepecky Mamut Dec 1 '17 at 13:18
3
$\begingroup$

In addition to using PlotStyle->None as suggested by @Kuba, you can also do:

Post-process to remove the Line primitives:

Plot[Sin[x], {x, 0, 2 Pi}, Filling -> {1 -> 0.5}] /. _Line :> Sequence[]

enter image description here

Plot[{Sin[x], Sin[x] - 0.5}, {x, 0, 2 Pi}, Filling -> {1 -> {2}}] /. _Line :> Sequence[] 

enter image description here

Use ParametricPlot with options BoundaryStyle -> None and Mesh -> None:

ParametricPlot[{x, t Sin[x] + (1 - t) .5}, {x, 0, 2 Pi}, {t, 0, 1}, 
 BoundaryStyle -> None, Mesh -> None, AspectRatio -> 1/GoldenRatio, Frame -> False]

enter image description here

ParametricPlot[{x, t Sin[x] + (1 - t) (Sin[x] - 0.5)}, {x, 0, 2 Pi}, {t, 0, 1}, 
 BoundaryStyle -> None, Mesh -> None, AspectRatio -> 1/GoldenRatio, Frame -> False]

enter image description here

$\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.