\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{autonode}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=6cm,height=4cm]
  % Deliberately omit `auto node placement`: the library must diagnose the
  % missing lifecycle once, even though more than one label is registered.
  \addplot[domain=0:2] {x}
    \pgfplotsautonode[preferred pos=.4]{$y=x$};
  \addplot[domain=0:2] {2-x}
    \pgfplotsautonode[preferred pos=.6]{$y=2-x$};
\end{axis}
\end{tikzpicture}
\end{document}
