% Load the ConTeXt PGFPlots frontend, then the autonomous library. \usemodule[t][pgfplots] \pgfplotsset{compat=1.18} \usepgfplotslibrary{autonode} \starttext \tikzpicture \axis[ width=9cm, height=6cm, grid=both, auto node placement, auto node debug=summary, auto node algorithm=repair, auto node failure mode=allow-minimal-overlap ] \addplot[blue,thick,domain=0:4,samples=40] {x} \pgfplotsautonode[preferred pos=0.65,sloped=true]{$y=x$}; \addplot[red,thick,domain=0:4,samples=40] {4-x} \pgfplotsautonode[preferred pos=0.35,sloped=true]{$y=4-x$}; \endaxis \endtikzpicture \stoptext .