# How do I name a plot in tikz and use it for intersections?

I want to create a figure with 3 plots, a vertical reference line, and marks at the intersections of each plot with the reference line. The plots come from an external table.

Plotting works, but naming the plot for usage with the intersections library does not. Here is an example:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[log basis x=10,log basis y=10]
\node[coordinate] (Ref) at (axis cs:1,1) {};
\node[coordinate] (RefPathStart) at (Ref |- current axis.south east) {};
\node[coordinate] (RefPathEnd) at (Ref |- current axis.north east) {};
\path[name path=RefPath] (RefPathStart) -- (RefPathEnd);
\fill [red,opacity=0.5,name intersections={of=SProPath and RefPath}]
(intersection-1) circle (2pt);
\end{loglogaxis}
\end{tikzpicture}
\end{document}


I'm getting the following errors:

! Package tikz Error: I do not know the path named SProPath'. Perhaps you misspelt it.
! Package pgf Error: No shape named intersection-1 is known.


The path SProPath should be known to tikz. Is my way of naming the plot wrong? How can I create intersection between "drawn" paths and plots?

-
Perhaps there is some sort of scoping problem going on, since addplot frees local variables after its visualization. Does name path global make a difference? I remember that Jake posted something related some time ago... – Christian Feuersänger Jul 5 '11 at 16:17
I've tried, but name path global does not work either. I'll have to find the problem Jake posted - or can you link to it? It doesn't seem to be tagged with intersections. – Christoph Jul 5 '11 at 17:40
I believe it was [tex.stackexchange.com/questions/21408/… ... but there it seemed to work. Is that related to your problem? – Christian Feuersänger Jul 5 '11 at 18:10
Changing the two name path to name path global seems to work for me. You should also have a look at the link Christian pointed out, and this related quetion on clearing paths named with name path global – Peter Grill Jul 5 '11 at 19:32
Here is the graph I get after using name path global – Peter Grill Jul 5 '11 at 19:38

As has been said in the comments, \addplot commands are executed in their own scope, so the name given to a path using name path will be lost immediately. To get around this, you can use name path global instead of name path, which will make the name available in all other scopes.
The same is true for the other path in your example: TikZ commands like \path and \draw inside an axis environment are not executed immediately, but only after the rest of the plot has been drawn. For this, each of the \path commands is wrapped in its own scope again. So you could either use name path global for the path as well, or you could pass the the \path and the \fill commands to a \pgfplotsextra{...} command. This will make sure both commands are executed in the same scope after the plot has been drawn, so name path global` is not needed.