\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{autonode}
\begin{document}
\begin{tikzpicture}
\begin{axis}[auto node placement,
  auto node debug=summary,
  auto node failure mode=hide-low-priority,
  width=6cm,height=4cm]
  \addplot[domain=0:2] {x*x}
    \pgfplotsautonode[preferred pos=.65,sloped=true]{$y=x^2$};
  % The coincident label forces the failure policy to run.  Because the policy
  % key follows `auto node placement`, this also guards key-order independence.
  \addplot[domain=0:2] {x*x}
    \pgfplotsautonode[preferred pos=.65,sloped=true]{$y=x^2$};
\end{axis}
\end{tikzpicture}

% A second, logarithmic and anisotropic axis verifies that the first axis was
% completely reset and that canvas-space tangents remain usable afterwards.
\begin{tikzpicture}
\begin{axis}[auto node placement,
  auto node debug=summary,
  auto node algorithm=repair,
  auto node bbox mode=oriented,
  auto node failure mode=error,
  xmode=log,ymode=log,
  width=8cm,height=4cm]
  \addplot[domain=1:100,samples=50] {sqrt(x)}
    \pgfplotsautonode[preferred pos=.55,sloped=true,
      candidate strategy=adaptive,normal shift=4pt]{$y=\sqrt{x}$};
\end{axis}
\end{tikzpicture}
\end{document}
