# How to Fill Area between 3 Functions / Curves?

**URL:** https://discourse.julialang.org/t/how-to-fill-area-between-3-functions-curves/91954
**Category:** General Usage
**Tags:** plotting, plots
**Created:** [December 21, 2022, 1:38pm UTC](https://discourse.julialang.org/t/how-to-fill-area-between-3-functions-curves/91954 "2022-12-21T13:38:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 21, 2022, 1:38pm UTC](https://discourse.julialang.org/t/how-to-fill-area-between-3-functions-curves/91954/1 "2022-12-21T13:38:16Z")

</div>

Hi all,

it is more than 2 curves problem now, I want to fill an area / region between 3 curves.

![Capture d’écran_2022-12-21_20-35-03](https://global.discourse-cdn.com/julialang/original/3X/0/c/0c7140267fbff397b320ef8fd9a185c70ba259f7.png)

Currently I can only manage to fill area between 2 curves:

```julia
using Plots, LaTeXStrings, Roots, SymPy
gr()

x = collect(range(-4, 2, length= 100))
f1(x) = x + 6
f2(x) = x^3
f3(x) = -x/2

plot(f1,-5,5, xtick=-5:5:5, xlims=(-5,5), ylims=(-10,10), 
	framestyle=:zerolines,
	label=L"y = x + 6", legend=:topleft)
plot!(f2,-5,5, xtick=-5:5:5, xlims=(-5,5), ylims=(-10,10), 
	framestyle=:zerolines,
	label=L"y = x^{3}", legend=:topleft)
plot!(f3,-5,5, xtick=-5:5:5, xlims=(-5,5), ylims=(-10,10), 
	framestyle=:zerolines,
	label=L"2y + x = 0", legend=:topleft)

plot!(x, f1, fillrange = f3, fillalpha = 0.35, c = 1, 
	label ="", legend=:topleft)

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [December 21, 2022, 1:48pm UTC](https://discourse.julialang.org/t/how-to-fill-area-between-3-functions-curves/91954/2 "2022-12-21T13:48:45Z")

</div>

One way (\*edited):

```julia
using ImplicitEquations, Plots; gr()

f1(x) = x + 6; f1(x,y) = f1(x)
f2(x) = x^3; f2(x,y) = f2(x)
f3(x) = -x/2; f3(x,y) = f3(x)
              	    f4(x,y) = y

plot((f4 ≦ f1) & (f4 ≧ f2) & (f4 ≧ f3), ylims=(-10,10), fc=:blues, widen=false) # \leqq[tab], \geqq[tab]
plot!(f1, -5, 5, c=:black)
plot!(f2, c=:black)
plot!(f3, c=:black)

```

![Plots_ImplicitEquations_area_between_3_functions](https://global.discourse-cdn.com/julialang/original/3X/5/0/5072893e2a99d38d650189b617ff2c288bc93920.png)

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [December 22, 2022, 8:13am UTC](https://discourse.julialang.org/t/how-to-fill-area-between-3-functions-curves/91954/3 "2022-12-22T08:13:35Z")

</div>

That’s the one, so we need `ImplicitEquations` along with Plots…

---

<div class="post-metadata">

### Author: ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)
#### Post date: [December 22, 2022, 10:13am UTC](https://discourse.julialang.org/t/how-to-fill-area-between-3-functions-curves/91954/4 "2022-12-22T10:13:06Z")

</div>

It freezes me at this point. what am I missing?

```julia
julia> plot!(f1, -5, 5, c=:black)
ERROR: MethodError: no method matching f1(::Float64)
Closest candidates are:

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [December 22, 2022, 10:18am UTC](https://discourse.julialang.org/t/how-to-fill-area-between-3-functions-curves/91954/5 "2022-12-22T10:18:49Z")

</div>

Sorry, the functions were first defined as per Freya’s original post with single variable `x`, then I extended them to two variables `x` and `y`, so adding methods to the same function names.

To run as standalone, we could do:

```julia
plot!(x->f1(x,x), -5, 5, c=:black)
# etc.

```

_NB: edited it in post above_
