# Converting unit to coordinate works for x-coordinate, but not for y-coordinate

By Jake's help I received a solution (in principle) for an "older" version of this question here, i.e. to extract/convert units in the data to local measures.

It works for x, yet unexpectedly fails for the y-coordinate.

Why does \pgfplotsconvertunittocoordinate not work twice for the same point? Is there some additional code needed?

## Data

http://pastebin.com/5AkHFZhh

## MWE

\documentclass[
a4paper
]{scrartcl}

\usepackage{
lmodern,
amsmath
}
\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.4] (A) coordinate [pos=0.6] (B);
\filldraw let \p1= (A) in (\x1,\y1) circle [radius=1pt] node[pin={270:({{\pgfplotsconvertunittocoordinate{x}{\x1}\pgfmathprintnumber[fixed,precision=1]{\pgfmathresult}}};{{\pgfplotsconvertunittocoordinate{y}{\y1}\pgfmathprintnumber[fixed,precision=1]{\pgfmathresult}}})}] {};
\draw (A) -| (current axis.west) coordinate (Ay) node[midway, above right=2pt, fill=white] {$$\simeq -2$$};
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}

-

In order to get you going, there are some alternatives:

There is a feature to access the coordinates of a anything around pos: \pgfplotspointplotattime{0.4} . This is probably the most simple way, although it is not quite the way one wants it to be:

\documentclass{standalone}

\usepackage{
lmodern,
amsmath
}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

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

\listfiles

\begin{document}

\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.4,pin={270:{%
\pgfplotspointplotattime{0.4}%
$(\pgfmathprintnumber[fixed,precision=1] {\pgfkeysvalueof{/data point/x}}; \pgfmathprintnumber[fixed,precision=1] {\pgfkeysvalueof{/data point/y}})$
}}] (A);
\filldraw let \p1= (A) in (\x1,\y1) circle [radius=1pt] ;
\draw (A) -| (current axis.west) coordinate (Ay) node[midway, above right=2pt, fill=white] {$$\simeq -2$$};
\end{axis}
\end{tikzpicture}

\end{document}


Details for this approach are in section Placing Nodes on Coordinates of a Plot in the pgfplots manual.

Alternative solutions (which are closer to what you expect) are outline by @Jake. A similar (equivalent) solution for your plot would be to add disabledatascaling to the option list of the axis.

That said, your question is actually the feature request "This is a PGF point. Please give me the associated high level coordinate". I have taken a note on the todo list for pgfplots.

The implementation of this feature request will go along the suggestions of @Jake.

Sorry for causing confusion with \pgfplotsconvertunittocoordinate: this routine should not be part of the manual at all as it use if for internal routines (only). I will remove it from the manual and insert a suitable function once it is ready.

-
Ha, that is incredible–it actually is a value of 2 for y! That was one sharp estimate I did there. Well I find your code quite readable as well and will gladly use it, when you say pgfplotsconvertunittocoordinate is not intended to be used for that kind of operation.. and especially when the good code can be found in the manual. Silly me, I glanced over that relevant page (299) yesterday but didn't realize it was the one. Having said that, I think the feature is already implemented. – henry Apr 30 '14 at 11:45
Well, accessing logical coordinates for something identified by means of pos=0.4 is implemented. But accessing logical coordinates for some node label (A) is not. And the current solution for pos=0.4 feels strange: sometimes one needs to provide the argument {0.4} sometimes not... well, it is how it is. But I am glad you find it usable. – Christian Feuersänger Apr 30 '14 at 15:44

This happens because PGFPlots rescales and shifts units for axes with small or large ranges. In this case, the x axis is unscaled, but the y axis is shifted and scaled. In order to get the correct values, you need to undo the transformation. The easiest way to do this is to pass the value through \pgfplotscoordmath{<axis>}{datascaletrafo inverse to fixed}{<value>}:

\documentclass[
a4paper
]{scrartcl}

\usepackage{
lmodern,
amsmath
}
\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 {
0 -10
130 10
} coordinate [pos=0.4] (A) coordinate [pos=0.6] (B);
\filldraw let \p1= (A) in (\x1,\y1) circle [radius=1pt] node[pin={270:({{%
\pgfplotsconvertunittocoordinate{x}{\x1}%
\pgfplotscoordmath{x}{datascaletrafo inverse to fixed}{\pgfmathresult}%
\pgfmathprintnumber[fixed,precision=1]{\pgfmathresult}}};{{%
\pgfplotsconvertunittocoordinate{y}{\y1}%
\pgfplotscoordmath{y}{datascaletrafo inverse to fixed}{\pgfmathresult}%
\pgfmathprintnumber[fixed,precision=1]{\pgfmathresult}}})}] {};
\draw (A) -| (current axis.west) coordinate (Ay) node[midway, above right=2pt, fill=white] {$$\simeq -2$$};
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}

-