I can get intersections to work in TikZ, but not PGF plots. I defined a command to show the intersections to make sure that it is identical in both cases. Commenting out the \ShowIntersection
line in the 2nd graph results in a syntax error. Is there a different way to name the curves in PGF plots?
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{intersections}
\begin{document}
% Define this as a command to ensure that it is same in both cases
\newcommand*{\ShowIntersection}{
\fill
[name intersections={of=GraphCurve and HorizontalLine, name=i, total=\t}]
[red, opacity=1, every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\t}{(i-\s) circle (2pt)
node [above left] {\s}};
}
\begin{tikzpicture}
\draw[name path=GraphCurve, mark=none, domain=-2.5:2.5, thick]%
plot ({\x},{\x*\x});%
\draw [red, thick, name path=HorizontalLine]
(-2.5,3) -- (2.5,3);%
\ShowIntersection% Works fine here
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}
\addplot[name path=GraphCurve, mark=none, domain=-2.5:2.5, thick]%
({x},{x*x});%
\addplot [red, thick, name path=HorizontalLine]
coordinates{(-2.5,3) (2.5,3)};%
%\ShowIntersection% Error: Do not know path "GraphCurve"
\end{axis}
\end{tikzpicture}
\end{document}