# Filling the area delimited by several curves

I'm trying to draw the feasible set of a maximization problem. I've been able to draw the boundary of it, but I'm struggling to shade it. I understand that my fill between statement fills the area delimited by the y-axis (from 0 to 1) and f_2, but it's not clear to me at all what part of the statement is actually limiting the shading to occur between 0 and 1. I'd like to modify the statement so it limited the shading to (Sqrt[14]/5,1) and then add another that shaded the area between the y-axis and f_5 (0,Sqrt[14]/5).

Alternatively, I'd be happy if I could fill in white the area between f_2 and f_5 from the intersection down. To this last end, I've tried adding

\addplot[fill=none] fill between [of=constraint_2 and constraint_5, split, every segment no 1/.style={fill,blue},on layer={axis background}];


right after the previous fill between instruction, and this indeed solves my problem. However, I feel it's an awkward solution.

Of course, I'm open to other, better solutions. Here is my MWE

\documentclass{article}
\usepackage{tikz,pgfplots}

\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{figure}
\centering
\footnotesize
\begin{tikzpicture}
\begin{axis}[
xlabel={$q_1$},
ylabel={$q_2$},
every axis x label/.style={at={(ticklabel* cs:1)},anchor=west},
every axis y label/.style={at={(ticklabel* cs:1)},anchor=south},
ticks=none,
axis x line=bottom,
axis y line=left,
xmin=0, xmax=2.2,
ymin=0, ymax=2,
y axis line style={name path=yaxis},
]
name path=constraint_2,
domain=0:sqrt(2),
samples=200,
y filter/.expression={x==sqrt(2)?0:y},
thick,
] {sqrt(2-x^2)};
name path=constraint_5,
domain=0:sqrt(122/75),
samples=200,
y filter/.expression={x==sqrt(122/75)?0:y},
thick,
] {sqrt((122/25-3*x^2)/1)};
\addplot[gray,opacity = 0.1] fill between [of=yaxis and constraint_2, reverse=false, soft clip={(-1,-1) rectangle (1,1)}, on layer={axis background}];
\addplot[fill=none] fill between [of=constraint_2 and constraint_5, split, every segment no 1/.style={fill,blue},on layer={axis background}];
domain = 0:7,
samples =2,
thick
] {1};
\node at (axis cs: 1,1.6) {$f_5$};
\node at (axis cs: 0.45,1.47) {$f_2$};
\node at (axis cs: 1.9,1.07) {$f_1$};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}


and its output

I don't fully understand what you want to achieve, but it may be easier to use a regular \fill command (in combination with a helper \path) and the intersection segments option if you want to fill the area defined by the two axes, f1, f2 and f5.

The following code first creates a named path that combines the relevant sections of f2 and f5 and then combines this path with f1 (which I named constraint_3). Since your plots start and end at y = 0 and x = 0 respectively, it is then easy to use this combined path to create a polygon with another point at the origin and fill it:

\documentclass{article}
\usepackage{tikz,pgfplots}

\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{figure}
\centering
\footnotesize
\begin{tikzpicture}
\begin{axis}[
xlabel={$q_1$},
ylabel={$q_2$},
every axis x label/.style={at={(ticklabel* cs:1)},anchor=west},
every axis y label/.style={at={(ticklabel* cs:1)},anchor=south},
ticks=none,
axis x line=bottom,
axis y line=left,
xmin=0, xmax=2.2,
ymin=0, ymax=2,
y axis line style={name path=yaxis},
]
name path=constraint_2,
domain=0:sqrt(2),
samples=200,
y filter/.expression={x==sqrt(2)?0:y},
thick,
] {sqrt(2-x^2)};
name path=constraint_5,
domain=0:sqrt(122/75),
samples=200,
y filter/.expression={x==sqrt(122/75)?0:y},
thick,
] {sqrt((122/25-3*x^2)/1)};
name path=constraint_3,
domain = 0:7,
samples = 2,
thick
] {1};
\path[name path=helper_path, intersection segments={of=constraint_2 and constraint_5, sequence={L1 -- R2}]}];
\fill[gray, opacity=0.1, intersection segments={of=constraint_3 and helper_path, sequence={L1 -- R2}]}] -- (0,0) -- cycle;
\node at (axis cs: 1,1.6) {$f_5$};
\node at (axis cs: 0.45,1.47) {$f_2$};
\node at (axis cs: 1.9,1.07) {$f_1$};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}


I have no idea about what you describe, so I just fill some random areas:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center, axis equal,
xlabel={$q_1$}, ylabel={$q_2$},
every axis x label/.style={at={(ticklabel* cs:1)},anchor=west},
every axis y label/.style={at={(ticklabel* cs:1)},anchor=south},
ticks=none,
xmin=0, xmax=2.2,
ymin=0, ymax=2,
y axis line style={name path=yaxis},
]
name path=constraint_2,
domain=0:sqrt(2),
samples=200,
y filter/.expression={x==sqrt(2)?0:y},
thick,
] {sqrt(2-x^2)} node[above, pos=0.2]{$f_2$};
name path=constraint_5,
domain=0:sqrt(122/75),
samples=200,
y filter/.expression={x==sqrt(122/75)?0:y},
thick,
] {sqrt(122/25-3*x^2)} node[above right, pos=0.4]{$f_5$};
name path=constraint_1,
domain=0:2.2, samples=2,
thick] {1} node[above, pos=0.8]{$f_1$};
\fill ({sqrt(14)/5},1) circle[radius=1.5pt] node[pin={[pin distance=1.2cm]40:{$\scriptscriptstyle \left(\frac{\sqrt{14}}{5} , 1\right)$}}]{};
\addplot[gray, opacity=0.5] fill between [of=yaxis and constraint_2, reverse=false];
\addplot[red, opacity=0.5] fill between [of=constraint_1 and constraint_2,
soft clip={(0,0) rectangle ({sqrt(14)/5},2)},
];
\addplot[fill=none] fill between [of=constraint_2 and constraint_5, split,
every segment no 1/.style={fill, green}
];
\addplot[blue, opacity=0.5] fill between [of=yaxis and constraint_2,
soft clip={(0,{sqrt(14)/5}) rectangle (2,1)},
];
\addplot[blue, opacity=0.5] fill between [of=yaxis and constraint_5,
soft clip={(0,0) rectangle (2,{sqrt(14)/5})},
];
\end{axis}
\end{tikzpicture}
\end{document}