# Overlap filled area plots

I have a series of plots that are filled with fill between. After I produce the plots, I draw a line which goes from the center of the area to an external point. I would like the line to disappear under a certain area. Until now I was able to produce just this

based on the following instructions

\documentclass[10pt]{article}

\usepackage{amsmath,bm}
\usepackage{amssymb}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{tikzscale}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}
\begin{axis}[domain=0:pi/2,
xmin=-1.5, xmax=2]

name path=A,
thick,
color=blue,
]  {sin(deg(x))};

name path=B,
thick,
color=green,
]  {2*sin(deg(x))};

name path=C,
thick,
color=red,
]  {3*sin(deg(x))};

\addplot [forget plot, mark=none,  black] coordinates { (-0.5,0.5) (1,0.5)};

\addplot [forget plot, mark=none,  black] coordinates { (-0.5,1) (1,1)};

\addplot [forget plot, mark=none,  black] coordinates { (-0.5,2) (1,2)};

\node at (axis cs:-0.5,0.5) [anchor=east] {$sin(x)$};
\node at (axis cs:-0.5,1) [anchor=east] {$2*sin(x)$};
\node at (axis cs:-0.5,2) [anchor=east] {$3*sin(x)$};

\end{axis}
\end{tikzpicture}

\end{document}

• Sorry, but what do you mean by "disappear under a certain area"? Could you add a sketch to your image to show what you want to achieve? Commented Mar 10, 2021 at 7:11
• Hello Stefan, thank you for your reply. For example, I want the black line associated with sin(x) to be visible over the red and green are, while disappearing under the blue one, and so on for the other lines. Is it clear now?
– Fly
Commented Mar 10, 2021 at 7:16

If I understood you comment to question correctly, than you after something like this:

\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.17}

\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:pi/2,
xmin=-1.5, xmax=2,
domain=0:pi/2,
]

\addplot[red, semitransparent]   fill between[of=C and axis];
\addplot[green, semitransparent] fill between[of=B and axis];
\addplot[blue, semitransparent]  fill between[of=A and axis];

\draw   (1,0.50) -- (-0.5,0.50) node[left] {$\sin(x)$}
(1,1.25) -- (-0.5,1.25) node[left] {$2*\sin(x)$}
(1,2.00) -- (-0.5,2.00) node[left] {$3*\sin(x)$};
\end{axis}
\end{tikzpicture}
\end{document}


For fill color is used semitransparent option that curve of function sin(x) is better visible. In diagram code I also took liberty for make it shorter and simpler.

Addendum (1): You may liked diagram with tick of function domain in shown in radians:

for this diagram you only need to add to axis option the following code lines:

             xtick={0, pi/6, pi/3, pi/2},
xticklabels={0,$\pi/6$,$\pi/3$,$\pi/2$},
xticklabel style = {font=\footnotesize},


Addendum (2): Considering OP comment below this answer, which make problem more clear, the one of possible (general) solution is employ ZikZ library intersections:

\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\pgfplotsset{compat=1.17}

\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:pi/2,
xmin=-1.5, xmax=2,
xtick={0, pi/6, pi/3, pi/2},
xticklabels={0,$\pi/6$,$\pi/3$,$\pi/2$},
xticklabel style = {font=\footnotesize},
domain=0:pi/2,
every axis plot post/.append style={draw=none}
]

\addplot[red, semitransparent]   fill between[of=C and axis];
\addplot[green, semitransparent] fill between[of=B and axis];
\addplot[blue, semitransparent]  fill between[of=A and axis];

\path [name path=A1] (-0.5,0.50) node[left] (a) {$\sin(x)$} -- (pi/2,0.50);
\path [name path=B1] (-0.5,1.25) node[left] (b) {$\sin(x)$} -- (pi/2,1.25);
\path [name path=C1] (-0.5,2.00) node[left] (c) {$\sin(x)$} -- (pi/2,2.00);

\draw [name intersections={of=A and A1, by=a1}] (a) -- (a1);
\draw [name intersections={of=B and B1, by=b1}] (b) -- (b1);
\draw [name intersections={of=C and C1, by=c1}] (c) -- (c1);
\end{axis}
\end{tikzpicture}
\end{document}


Edit: Corrected are errors in naming of x ticks.

• Hello Zarco, probably my request was not really clear. What I would like is the horizontal lines connecting one area to the labels (sin(x), 2*sin(x) or 3*sin(x)) to disappear under the filled area.
– Fly
Commented Mar 10, 2021 at 8:05
• It's then a problem of layers. This will definitely help tex.stackexchange.com/questions/350458/…
– JeT
Commented Mar 10, 2021 at 11:14
• @Fly, sorry, but now is obvious that your question is not clear at all. Commented Mar 10, 2021 at 11:14
• @Fly, see addendum to my answer. Commented Mar 10, 2021 at 11:43
• @Fly, with my code as are in addendum, this cannot be a case (tested again). Commented Mar 10, 2021 at 12:44

If I have well understood the request, you need to adjust the x coordinate so that it corresponds to a point on the graph. For this we have to use the inverse functions asin(y), asin(y/2) and asin(y/3)

\documentclass[10pt]{article}

\usepackage{amsmath,bm}
\usepackage{amssymb}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage{tikzscale}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}

\begin{axis}[domain=0:pi/2,
xmin=-1.5, xmax=2]

name path=A,
thick,
color=blue,
]  {sin(deg(x))};

name path=B,
thick,
color=green,
]  {2*sin(deg(x))};

name path=C,
thick,
color=red,
]  {3*sin(deg(x))};

coordinates { (-0.5,0.5) (rad(asin(0.5)),0.5)}; % <-----------

coordinates { (-0.5,1) (rad(asin(1/2)),1)}; % <-------------

\node at(axis cs:-0.5,0.5)[anchor=east] {$sin(x)$};
\node at (axis cs:-0.5,1) [anchor=east]{$2*sin(x)$};
\node at (axis cs:-0.5,2) [anchor=east]{$3*sin(x)$};

\end{axis}
\end{tikzpicture}

\end{document}


• Hello Adif, thank you for the reply. It's exactly what I was searching, but what about a more general approach? In reality my curves are defined not by analytical functions.
– Fly
Commented Mar 10, 2021 at 10:08
• @Fly If the functions are defined by a list of coordinates then choose one of them and draw a line from this point to the text node Commented Mar 10, 2021 at 11:11