% Modified from https://tex.stackexchange.com/a/261567.
\documentclass{standalone}
\usepackage[active,tightpage]{preview}
\usepackage{amsmath}
\usepackage[dvisvgm]{graphicx}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta,intersections}

\usepackage{anyfontsize}
\renewcommand{\normalsize}{\fontsize{14pt}{16pt}\selectfont}

\DeclareMathOperator{\dom}{dom}

\pgfmathdeclarefunction{func}{1}{%
  \pgfmathparse{max(6-3*(#1-1),3-2*(#1-2),1-(#1-3),0+(#1-4),2+2*(#1-6))}%
}

\pgfplotsset{compat=1.18}
\makeatletter
\pgfplotsset{
    mark max/.style={
        point meta rel=per plot,
        visualization depends on={x \as \xvalue},
        scatter/@pre marker code/.code={%
        \ifx\pgfplotspointmeta\pgfplots@metamax
            \def\markopts{mark=none}%
            \coordinate (maximum);
        \fi
            \def\markopts{mark=none}
            \expandafter\scope\expandafter[\markopts]
        },%
        scatter/@post marker code/.code={%
            \endscope
        },
        scatter
    }
}
\tikzset{
    point/.style={
        draw, circle, fill, inner sep=-1.5pt
    }
}

% Syntax
% \DrawEpigraph[<additional options>]{<min domain x>}{<max domain x>}{<shift on the left>}{<shift on the right>}
\newcommand\DrawEpigraph[6][draw=white,top color=red!05,bottom color=red!45]{
  \coordinate (plot-left) at ([yshift=#4]axis cs:#2,\pgfplots@metamax);
  \coordinate (plot-right) at ([yshift=#5]axis cs:#3,\pgfplots@metamax);
  \path[name path=diagonal,draw=none] (plot-left) -- (plot-right);
  \addplot[#1] fill between[of=#6 and diagonal];
}
\makeatother

\PreviewEnvironment{tikzpicture}

\begin{document}        

\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xlabel={$g(x)$},
  ylabel={$f(x)$},
  xtick={\empty},
  ytick={\empty},
  domain=1:7,
  ymin=0,
  ymax=7,
  xmin=0,
  xmax=7.5,
  clip=false,
  scale=2
] 
\node[below left] at (axis cs:0,0) {$O$};
\draw[dashed] (3,0) node [below] {$y$} -- (3,7);
\draw[dashed] (3,1) -- (0,1) node [left] {$v(y)$};
\draw[-] (3.75,0) -- node [pos=0.5,below left] {$k=\lambda$} 
    (0,5) node[left] {$h(\lambda)$};
% The curve
\addplot [dashed,mark max,black,thick,name path=B,samples=1000] plot {func(x)};
% The Epigraph
\DrawEpigraph{1}{7}{40}{40}{B}
% Lines and labels
\node[point,fill=red]  at (axis cs: 1, 6) {};
\node[point,fill=red]  at (axis cs: 2, 3) {};
\node[point,fill=blue] at (axis cs: 2, 5) {};
\node[point,fill=red]  at (axis cs: 3, 1) {};
\node[point,fill=blue] at (axis cs: 3, 2) {};
\node[point,fill=blue] at (axis cs: 3, 3) {};
\node[point,fill=blue] at (axis cs: 3, 5) {};
\node[point,fill=red]  at (axis cs: 4, 0) {};
\node[point,fill=blue] at (axis cs: 4, 3) {};
\node[point,fill=blue] at (axis cs: 4, 4) {};
\node[point,fill=blue] at (axis cs: 4, 6) {};
\node[point,fill=red]  at (axis cs: 5, 1) {};
\node[point,fill=blue] at (axis cs: 5, 4) {};
\node[point,fill=red]  at (axis cs: 6, 2) {};
\node[point,fill=blue] at (axis cs: 6, 3) {};
\node[point,fill=blue] at (axis cs: 6, 4) {};
\node[point,fill=red]  at (axis cs: 7, 4) {};
\node[point,fill=blue] at (axis cs: 7, 5) {};
\end{axis}
\end{tikzpicture}

\end{document}
