# Extracted coordinates have wrong value

I am unable to get the right coordinate values for (A) and (B) in the following axis. Did I misunderstand some conversion step or is it because of the data?

## MWE

\documentclass[
a4paper
]{scrartcl}

\usepackage{
newtxtext,
amsmath,
tikz,
pgfplots
}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usetikzlibrary{
calc
}

\listfiles

\begin{document}

\begin{center}
\begin{tikzpicture}[font=\small]
\begin{axis}[
height=6cm,
width=14cm,
%
scale only axis=true,
xlabel={Distance in mm},
ylabel={Voltage in volt},
]
\addplot [sharp plot, no marks, x=Wegnormiert] table [col sep=tab] {data.txt} coordinate [pos=0.5] (A) coordinate [pos=0.6] (B);
\draw (A) -| (B);
\filldraw let \p1= (A) in (\x1,\y1) circle [radius=1pt] node[pin={[pin distance=1.1cm]270:{{\pgfmathparse{\x1}\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,pt}}}] {};
\filldraw let \p2= (B) in (\x2,\y2) circle (1pt) node[yshift=-0.5cm, pin=270:{{\pgfmathparse{\x2/2.845274}\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,mm}}] {};
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}


## Data

http://pastebin.com/5AkHFZhh

\documentclass[
a4paper
]{scrartcl}

\usepackage{
newtxtext,
amsmath,
subcaption,
biblatex
}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{
tikz,
pgfplots
}
\usetikzlibrary{
calc
}

\listfiles

\begin{document}

\begin{center}
\centering
\begin{tikzpicture}[font=\small]
\begin{axis}[
height=6cm,
width=14cm,
%
scale only axis=true,
xlabel={Distance in mm},
ylabel={Voltage in volt},
]
\addplot [sharp plot, no marks, x=Wegnormiert] table [col sep=tab] {data.txt} coordinate [pos=0.5] (A) coordinate [pos=0.6] (B);
\draw (A) -| (B);
%   \filldraw let \p1= (A) in (\x1,\y1) circle [radius=1pt] node[pin={[pin distance=1.1cm]270:{{\pgfmathparse{\x1}\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,pt}}}] {};
\filldraw let \p2= (B) in (\x2,\y2) circle (1pt) node[yshift=-0.5cm, pin=270:{{\pgfplotsconvertunittocoordinate{x}{\x2}\pgfmathprintnumber[fixed,precision=1]{\pgfmathresult}}}] {} node[yshift=0.5cm, pin={355:{{\pgfplotsconvertunittocoordinate{y}{\y2}\pgfmathprintnumber[fixed,precision=1]{\pgfmathresult}}}}] {};
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}


If I understand your question correctly, you want to label the points using logical units (i.e. using the same units as the axis ticks). To do that, you need to convert the paper units (in pt) that you get from the let syntax to logical coordinates. You can do this using \pgfplotsconvertunittocoordinate{<x/y/z>}{<value>}:

\documentclass{standalone}

\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
height=6cm,
width=14cm,
%
scale only axis=true,
xlabel={Distance in mm},
ylabel={Voltage in volt},
]
\addplot [sharp plot, no marks, x=Wegnormiert] table {
Wegnormiert abc
0 -10
130 10
} coordinate [pos=0.5] (A) coordinate [pos=0.6] (B);
\draw (A) -| (B);
\filldraw let \p1= (A) in (\x1,\y1) circle [radius=1pt] node[pin={[pin distance=1.1cm]270:{{\pgfplotsconvertunittocoordinate{x}{\x1}\pgfmathprintnumber[fixed,precision=1]{\pgfmathresult}}}}] {};
\filldraw let \p2= (B) in (\x2,\y2) circle (1pt) node[yshift=-0.5cm, pin=270:{{\pgfplotsconvertunittocoordinate{x}{\x2}\pgfmathprintnumber[fixed,precision=1]{\pgfmathresult}}}] {};
\end{axis}
\end{tikzpicture}

\end{document}

• Yes, you understood right. Great. :) However I tried to stack the commands for doing the same for the y-coordinate but it failed. Is it because of the yshift or does it not work like that? (see at the bottom of op for additional code with exemplary picture) – henry Apr 29 '14 at 14:22
• @henry: Sorry for not replying earlier, it took me a while to figure this out. In general, it's much preferred to post really minimal examples. Your code contains a lot of extra stuff (axis labels, the use of a pin instead of a node, the external data file) that make it harder to read and harder to see the actual issue. – Jake Apr 30 '14 at 8:49
• No problem at all! I wouldn't deem all the things you mentioned extra but now I know and iwll account for it the next time. I appreciate your effort. – henry Apr 30 '14 at 12:08

With the release of PGFPlots v1.16 it is now possible to store (axis) coordinates with \pgfplotspointgetcoordinates in data point, which then can be called by \pgfkeysvalueof. With this it is possible to add the labels you want.

For details please have a look at the comments in the code.

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% use this compat' level or higher to use the advanced positioning of
% the axis labels
compat=1.3,
}
\begin{document}
\begin{tikzpicture}[
font=\small,
]
\begin{axis}[
height=6cm,
width=14cm,
scale only axis=true,
xlabel={Distance in mm},
ylabel={Voltage in V},
]
% x=...' is an optional argument of table' and not \addplot'
% (it worked, because using the first column (x index=0') is the default.
%  That is the same reason why you don't have to state the y column.)
% All other options are default as well so they can be omitted.
% You need the empty bracket so the cycle list' isn't used to format
% the plot.
coordinate [pos=0.5] (A)
coordinate [pos=0.6] (B)
;

\draw (A) -| (B);

\filldraw (A) circle (1pt)
node [pin={%[pin distance=10mm]
below:
% -------------------------------------------------------------
% using \pgfplotspointgetcoordinates' stores the (axis)
% coordinates of e.g. the coordinate (A) in data point',
% which then can be called by \pgfkeysvalueof'
\pgfplotspointgetcoordinates{(A)}
$\pgfmathprintnumber{\pgfkeysvalueof{/data point/x}}$
% -------------------------------------------------------------
}] {};
% to avoid the (trial and error) yshift' first draw the circle ...
\filldraw (B) circle (1pt);
% ... then position the pin
\node at (A -| B) [pin={below:
\pgfplotspointgetcoordinates{(B)}
$\pgfmathprintnumber{\pgfkeysvalueof{/data point/x}}$
}] {};

% now draw the horizontal pins
\node at (A -| B) [pin={right:
\pgfplotspointgetcoordinates{(A)}
$\pgfmathprintnumber[fixed,precision=3]{\pgfkeysvalueof{/data point/y}}$
}] {};
\node at (B) [pin={right:
\pgfplotspointgetcoordinates{(B)}
$\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}$
}] {};
\end{axis}
\end{tikzpicture}
\end{document}