How to Fill Area between 3 Functions / Curves?

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

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

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)

One way (*edited):

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

6 Likes

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

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

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

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:

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

NB: edited it in post above

2 Likes