Mixing pgfplots and tikz has a few unforeseen hitches that can catch out the unwary.
The first is that \addplot doesn't render its path at the invocation time but rather it gets saved up for the end of the axis environment. So a path defined by \addplot is not available until after the axis environment ends. Fortunately, a pgfplots axis also affects normal TikZ \draw (and similar) commands so these also get gathered up and dealt with at the end of the axis environment. So you don't notice this in your situation, but it is worth knowing about.
The second is that \addplot also introduces lots of scopes, which introduce TeX groups, and so things that are defined locally don't last out of their groups. So the spath/save from the previous answer needs to be replaced by spath/save global to make the path global.
The third is that \addplot takes its key values by default in the pgfplots directory. So the spath key needs to have its absolute path and be invoked as /tikz/spath/save global.
\documentclass[10pt,convert={convertexe=magick,density=1000,outext=.png}]{standalone}
%\url{https://tex.stackexchange.com/q/650703/86}
\usepackage{tikz,pgfplots}
\usetikzlibrary{decorations.markings,spath3}
\tikzset{
message/.code={\message{this is message #1^^J}}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[/tikz/message=one,/tikz/spath/save global=test] coordinates {(0,0) (2,3) (5,5)};
\tikzset{message=two,spath/show=test} % path doesn't exist here
\begin{scope}
\clip (axis cs:1,1) rectangle (axis cs:4,4);
\draw[message=three,ultra thick, red,postaction={decorate},decoration={markings,mark=at position 0.5 with {\arrow{stealth}}}][spath/use=test];
\end{scope}
\tikzset{message=four}
\end{axis}
\end{tikzpicture}
\end{document}
The message key is included in the above to show how the order of things happens. In the code, there are four messages in the order one, two, three, and four. In the logfile, it produces:
this is message one
this is message two
Package spath3 Warning: Soft path test doesn't exist on line 17
this is message four
this is message one
this is message three
Note also that the test path doesn't exist when it is "shown" in the \tikzset line. It doesn't get defined until the end of the axis environment.
addplotintroduces lots of scopes and groupings. Does the code from the other answer work if you usespath/save globalinstead? – Andrew Stacey Jul 13 '22 at 21:28I do not know the key '\pgfplots\spath\save, the same forsave global– Pygmalion Jul 14 '22 at 05:49/tikz/spath/save global– Andrew Stacey Jul 14 '22 at 05:51/tikz/spath/save globalworks, great! Will you provide the answer? – Pygmalion Jul 14 '22 at 05:56