[Tex/LaTex] How to reference an axis label, e.g. xlabel

coordinateslabelspgfplotstikz-pgf

I'm new to that forum but it already helped a lot, thanks for this!

But now I really got stuck. Basically I'm looking for a possiblity to reference the xlabel of an axis in a TikZ picture. The intention is to read out the xlabel coordinates. Later on I would like to use them to position another node in a specific way with respect to the these coordinates.

With xlabel style={name=xlabel} I tried to assign the xlabel name in the axis options. Within the axis I wanted to point to it with xlabel.north (like it is possible to point to the axis itself with current axis.north).

Unfortunately it didn't work. I was told:

no shape named xlabel is known

So I guess, that naming the xlabel in the axis options is wrong. Is there a way to solve this problem?

I hope the question is stated such that one can understand what I'm trying to say…

Best Answer

You're probably trying to access the xlabel node before it's created (hard to tell without an example document).

If you put the drawing command inside the axis, the label won't exist yet (it gets placed only after the axis is finished). You'll have to put it outside the axis:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xlabel=X label,
    xlabel style={name=xlabel}
  ]
  \addplot {rnd};
  \end{axis}
  \draw [ultra thick, latex-] (xlabel.south east) -- ++(1,-1);
\end{tikzpicture}
\end{document}
Related Question