\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{autonode}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  width=8cm,height=5cm,
  xmin=0,xmax=1,ymin=0,ymax=1,
  auto node placement,
  auto node debug=summary,
  auto node failure mode=warn,
  clip=true]
  % The visible part is much shorter than the complete plot path.  Viewport-
  % aware sampling must nevertheless find a usable position for this label.
  \addplot[blue,domain=-30:30,samples=121] {0.5}
    \pgfplotsautonode[preferred pos=.5] {crossing};
  \addplot[red,domain=0.1:0.9,samples=21] {0.75}
    \pgfplotsautonode[preferred pos=.5] {inside};
  % This plot does not intersect the axis at all and must remain unlabelled.
  \addplot[black,domain=-2:-1,samples=10] {0.25}
    \pgfplotsautonode[preferred pos=.5] {invisible};
\end{axis}
\end{tikzpicture}
\end{document}
