1

I am really confused with how coordinates work inside the axis environment. Consider the following MWE:

\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmin=-4, xmax=4,
        ymin=-.02,ymax=1,
        width=0.5\textwidth,
        height=0.33\textwidth,
        xtick distance=1,
        xlabel={Ability [Logits]},
        ylabel={Probability}]
        \addplot[domain=-4.9:4.9,blue,samples=200,thick]
        {1/(1+exp(-(1.3*x-2.2)))};
%%%% Where is this node? %%%%
\node[rectangle,fill=white] (a) at (2,.5) {\footnotesize{\textcolor{blue}{label}}};
\end{axis}  

\end{tikzpicture} \end{document}

enter image description here

With the code above node (a) is nowhere to be seen in the tikz picture. I would expect it to appear at the specified location (2,0.5). Apparently it does not work this way and I do not understand what is going on exactly.

Torbjørn T.
  • 206,688
  • 2
    By default the coordinates of the basic TikZ macros \node, \draw etc. are not in the coordinate system of the axis. Either add \pgfplotsset{compat=1.11} (or some higher valid version number, see pgfplots manual) to change the default, or prepend axis cs: in the coordinates, e.g. (axis cs:2, 0.5). – Torbjørn T. Jul 01 '22 at 22:13
  • That is intersting to know! "axis cs:" is all I needed to know. Thank you! Unfortunately I can't give your answer the checkmark since you only commented. – YellowCake Jul 01 '22 at 22:28
  • I commented because several similar questions have been asked before, I meant to find a duplicate. – Torbjørn T. Jul 01 '22 at 22:50
  • 1
    @YellowCake the main problem here is that you ignored the pgfplots warning about not setting a compat level... – Rmano Jul 01 '22 at 23:27
  • Another benefit of setting the compat level is that the position of the ylabel will be improved, moved closer to the axis. – Torbjørn T. Jul 02 '22 at 10:29

0 Answers0