# Extract x and y coordinates when using intersectionlibary [duplicate]

Possible Duplicate:
Coordinates of intersections

I have the following minimal plot

\documentclass{standalone}

\usepackage{pgfplots}

\usetikzlibrary{intersections}

\newcommand*{\ShowIntersection}[2]{
\fill
[name intersections={of=#1 and #2, 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{document}
\begin{tikzpicture}
\begin{axis}[
scale only axis,
grid=major,
grid style={dashed, gray!30},
axis lines=middle,
inner axis line style={=>},
xlabel={\large $x$},
ylabel={\large $y$},
yticklabel style={inner ysep=0pt, anchor=south east},
ytick={-4,-3.5,...,7},
xticklabel style={inner xsep=0pt, anchor=north west},
xtick={-3,-2.5,...,5},
ymin=-0.25,
ymax= 4.24,
xmin=-0.25,
xmax= 4.25,
after end axis/.code={
\path (axis cs:0,0)
node [anchor=north west,yshift=-0.075cm] {0}
node [anchor=south east,xshift=-0.075cm] {0};
}
]
\ShowIntersection{a}{b}
\end{axis}
\end{tikzpicture}
\end{document}


and this works to automatically find the interesections between the lines. However how can I label the points with its x and y coordinates? Eg i want (2.57,2.64) to be shown above the point.

EDIT: Followings jakes advice, I got closer to a working solution with

\documentclass{standalone}

\usepackage{pgfplots}

\usetikzlibrary{intersections}

\makeatletter
\newcommand\transformxdimension[1]{
\pgfmathparse{((#1/\pgfplots@x@veclength)+\pgfplots@data@scale@trafo@SHIFT@x)/10^\pgfplots@data@scale@trafo@EXPONENT@x}
}
\newcommand\transformydimension[1]{
\pgfmathparse{((#1/\pgfplots@y@veclength)+\pgfplots@data@scale@trafo@SHIFT@y)/10^\pgfplots@data@scale@trafo@EXPONENT@y}
}
\makeatother

\newcommand*{\ShowIntersection}[2]{
\fill
[name intersections={of=#1 and #2, 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] {($\!\!\!$\pgfgetlastxy{\macrox}{\macroy}
\transformxdimension{\macrox}
\pgfmathprintnumber{\pgfmathresult},%
\transformydimension{\macroy}%
\pgfmathprintnumber{\pgfmathresult})}};
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
scale only axis,
grid=major,
grid style={dashed, gray!30},
axis lines=middle,
inner axis line style={=>},
xlabel={\large $x$},
ylabel={\large $y$},
yticklabel style={inner ysep=0pt, anchor=south east},
ytick={-4,-3.5,...,7},
xticklabel style={inner xsep=0pt, anchor=north west},
xtick={-3,-2.5,...,5},
ymin=-0.25,
ymax= 4.24,
xmin=-0.25,
xmax= 4.25,
after end axis/.code={
\path (axis cs:0,0)
node [anchor=north west,yshift=-0.075cm] {0}
node [anchor=south east,xshift=-0.075cm] {0};
}
]

• Give a name to the coordinate of the intersection, and use -| and |- syntax with the axis ends. – JLDiaz Aug 7 '12 at 13:42