This question already has an answer here:

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:

            \node [circle,fill,inner sep=2pt]  (d1) at (axis cs:4,2) {};
            \draw let \p1=(d1) in (d1) coordinate[label=below:\x1]{} ;

The label, which should give me the horizontal coordinate of the node, currently reads: 77.999988pt.

enter image description here

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.)

marked as duplicate by Stefan Pinnow pgfplots Jun 7 '18 at 15:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I guess these are absolute coordinates and pgfplots does some rescaling. You can check this by adjusting the width. – marmot 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
            \node [
                inner sep=2pt,
                    \pgfkeysvalueof{/data point/x}},
                    \pgfkeysvalueof{/data point/y}})$
            ]  (d1) at (axis cs:4,2) {};

image showing the result of above code

  • 1
    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
  • 1
    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

Not the answer you're looking for? Browse other questions tagged or ask your own question.