# how to shade the intersection of 3 lines [duplicate]

I was trying to shade the intersection of the following 3 lines, but don't know how to do that. Apparently, the coordinates of the 3 points of the triangle area are identifiable. Could anyone please help me with that? Thank you in advance.

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines = left,
xlabel = $x$,
ylabel = {$f(x)$},
ymin=0, ymax=5
]
%Below the red parabola is defined
domain=0:4,
samples=10,
color=red,
]
{2-0.5*x};
%Here the blue parabloa is defined
domain=0:4,
samples=10,
color=blue,
]
{(15-5*x)/3};

domain=0:4,
samples=10,
color=yellow,
]
{5*x-15};

\end{axis}
\end{tikzpicture}
\end{document}


## marked as duplicate by koleygr, Mensch, CarLaTeX, TeXnician, Stefan PinnowOct 29 '17 at 18:15

• Please do not post fragments of code only. Your example misses the preamble with the needed packages to be loaded – user31729 Oct 29 '17 at 16:25
• Off-topic: Please, go to your previous question and accept the given answer – koleygr Oct 29 '17 at 17:03

Here is a way:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines = left,
xlabel = $x$,
ylabel = {$f(x)$},
ymin=0, ymax=5
]
%Below the red parabola is defined
domain=0:4,
samples=10,
color=red,
]
{2-0.5*x};
%Here the blue parabloa is defined
domain=0:4,
samples=10,
color=blue,
]
{(15-5*x)/3};

domain=0:4,
samples=10,
color=yellow,
]
{5*x-15};
\addplot[blue!60] fill between[of=A and B,soft clip={domain=2.6:3}];
\addplot[blue!60,draw] fill between[of=C and A,soft clip={domain=3:3.1}];

\end{axis}
\end{tikzpicture}
\end{document}


I didn't solved the equations to find real points, and I suggest you to do it.

Output:

PS: If the above answers to your question, your question is duplicate of : pgfplots fillbetween with multiple curves

• The real domain of second fill is 3:17/5.5 – koleygr Oct 29 '17 at 17:00
• Thank you! You've answered my question and this is a duplicate of that link. I didn't understand that before, sorry~ – Darcy Pu Oct 29 '17 at 17:31
• Welcome... Happy TeXing... – koleygr Oct 29 '17 at 17:32

With \usetikzlibrary{intersections} you could (1.) compute the intersection points a,b and c and then (2.) fill the area between them.

intersection points:

\node[coordinate, name intersections = {of = A and B}] (a) at  (intersection-1) {};
\node[coordinate, name intersections = {of = A and C}] (b) at  (intersection-1) {};
\node[coordinate, name intersections = {of = B and C}] (c) at  (intersection-1) {};


Fill area

\fill[red](a) -- (b) -- (c);


MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines = left,
xlabel = $x$,
ylabel = {$f(x)$},
ymin=0, ymax=5
]
%Below the red parabola is defined
domain=0:4,
samples=10,
color=red,
]
{2-0.5*x};
%Here the blue parabloa is defined
domain=0:4,
samples=10,
color=blue,
]
{(15-5*x)/3};

domain=0:4,
samples=10,
color=yellow,
]
{5*x-15};