# Pgfplots: how to have “let” retrieve coordinates in the axis coordinate system? [duplicate]

This is a continuation of my previous question, but now I want to use pgfplots.

In an axis environment, I add a node using the axes coordinate system. I would like to use let to retrieve the coordinates of a node in the axes coordinate system.

In the example below:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=10,ymin=0,ymax=10]
\node [circle,fill,inner sep=2pt]  (d1) at (axis cs:4,2) {};
\draw let \p1=(d1) in (d1) coordinate[label=below:\x1]{} ;
\end{axis}
\end{tikzpicture}
\end{document}


The label, which should give me the horizontal coordinate of the node, currently reads: 77.999988pt. Where does that number come from?

Since the node is placed at (4,2), I would like instead get the label as 4 times 28.45274pt = 113.81096pt. (I would then transform it for display.)

• I guess these are absolute coordinates and pgfplots does some rescaling. You can check this by adjusting the width. – user121799 Jun 6 '18 at 18:18

You can use the \pgfplotspointgetcoordinate command to extract the x and y coordinates of a given coordinate/node. Is that what you are searching for?

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=10,ymin=0,ymax=10]
\node [
circle,
fill,
inner sep=2pt,
pin=above:{
\pgfplotspointgetcoordinates{(d1)}
$(\pgfmathprintnumber[fixed]{ \pgfkeysvalueof{/data point/x}}, \pgfmathprintnumber[fixed]{ \pgfkeysvalueof{/data point/y}})$
},
]  (d1) at (axis cs:4,2) {};
\end{axis}
\end{tikzpicture}
\end{document} • This is great. For future readers, I just want to point out that retrieving the coordinates can also be done for a node previously defined. \node (d2) at (axis cs:5,7) {}; \coordinate [ pin=above:{ \pgfplotspointgetcoordinates{(d2)} $(\pgfmathprintnumber[fixed]{ \pgfkeysvalueof{/data point/x}}, \pgfmathprintnumber[fixed]{ \pgfkeysvalueof{/data point/y}})$ } ] () at (d2); works too. – Peutch Jun 7 '18 at 14:05
• This is true. I just marked this question being a duplicate where you can also see this in action. – Stefan Pinnow Jun 7 '18 at 15:08
• Could you confirm that \pgfplotspointgetcoordinates only works within the axis environment? If so, is it possible to store their result and use them outside the axis environment? – Peutch Jun 7 '18 at 18:35
• I would guess so for the first question. For the second have a look at the command \Getxycoords in e.g. tex.stackexchange.com/a/426245/95441. With that you can globally store the coordinates in custom commands and use it "everywhere", also outside the tikzpicture environment. – Stefan Pinnow Jun 7 '18 at 18:52