[Tex/LaTex] Tikz Nodes do not take absolute coordinate values

nodestikz-pgf

this is my first post so please correct me if I am doing something wrong. I wish to draw a tikzpicture with nodes and use here absolute coordinates. I don't know why, but somehow my coordinates seem to be relative and not absolute. In this code sample, for instance, one node should be positioned at (0,0) but instead is somewhere in the negative area of the coordinate system. What am I doing wrong?

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\tikzset{>=latex}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\pgfplotsset{
width =0.9\textwidth,
height = 0.9\textwidth,
legend cell align=left,
legend pos=outer north east,
legend style={draw=none, anchor=north west, at={(1.1,1)},font=\Large,    
xmin=-124, xmax=160,
},
every tick label/.append style={font=\Large},
yticklabel style={text width=3em,align=right},
}

\begin{axis}[grid=major, ymin=-50, ymax=150]
\node(0) at (0,0)[rectangle,draw, minimum size = 5pt, fill = black,   
inner sep = 0pt]{};
\node(1) at (-5, 70)[minimum size = 3.7pt, fill= white, inner sep = 0pt, 
shape = circle, draw]{};
\node(2) at (-17, 69)[minimum size = 3.7pt, fill= white, inner sep = 0pt, shape = circle, draw]{};
\node(3) at (-19, 85)[minimum size = 3.7pt, fill= white, inner sep = 0pt, shape = circle, draw]{};
\node(4) at (9, 99)[minimum size = 3.7pt, fill= white, inner sep = 0pt, shape = circle, draw]{};
\node(5) at (15, 82)[minimum size = 3.7pt, fill= white, inner sep = 0pt, shape = circle, draw]{};

\end{axis}
\end{tikzpicture}
\end{document}

Best Answer

It is important to note that you are not only using TikZ, but also PGFPlots. As described in section 4.17.1 (Accessing Axis Coordinates in Graphical Elements) in the manual, there are different coordinate systems in PGFPlots:

  • axis cs: the axis coordinate system

  • rel axis cs: a relative coordinate system, where the complete axis vectors are normalized to 1

  • axis direction cs: allows to use relative positions and directions
  • axis description cs: useful for (of course) axis descriptions
  • ticklabel cs:,xticklabel cs:,yticklabel cs:,zticklabel cs: for positioning the tick labels
  • xticklabel* cs:,yticklabel cs:,zticklabel cs: are the same as the non-starred versions, but do not take the size of any tick labels into account

All of these are different from the default TikZ coordinate system. In your case, you'll probably want to use the axis coordinate system axis cs:, to place nodes at absolute coordinates within your axis. As @Thruston says in his comment, you can place a node within this (or any other of the above) coordinate system with

\node at (axis cs:0,0) {};

The developers of PGFPlots have designed PGFPlots to be fully backwards-compatible. New features, which would make old diagrams look different with a new version, are disabled by default and have to be enabled manually. This can be done with

\pgfplotsset{compat=*version*}

where *version* is the PGFPlots version number, e.g. 1.11 or 1.13. As shown in a comment by @Torbjørn T., from version 1.11 on, the axis cs: coordinate system is the default, so you don't need to specify it at every use. Thus, with \pgfplotsset{compat=1.13} in your preamble, the diagram will look as you'd expect, without any changes to your code.


A small note: You specify the options [minimum size=3.7pt, fill=white, inner sep=0pt, shape=circle, draw] for every drawn point. If you want to change that later, you'd have to go through all nodes and change it. Alternatively, you can specify a style with

\begin{tikzpicture}[scale=0.8,
    mydot/.style={minimum size=3.7pt, fill=white, inner sep=0pt, shape=circle, draw}
]
    \node[mydot] at (-5, 70) {};
\end{tikzpicture}

With that, you'll only have to specify the style once.