[Tex/LaTex] Axes in tikz, figure shows but there is a compiling error

tikz-pgf

I have the following code to draw four axes:

\begin{tikzpicture}
  \draw (-3,0) -- (3,0) node[below];
  \draw[shift={(0,0)}] (0pt,2pt) -- (0pt,-2pt) node[below];
  \draw (0,-3) -- (0,3) node[left];
  \draw[shift={(0,0)}] (2pt,0pt) -- (-2pt,0pt) node[left]; 
  \node[below] at (0,-3.20) {\footnotesize label1};
  \node[above] at (0,3.20) {\footnotesize label2};
  \node[right] at (3.20, 0) {\footnotesize label3};
  \node[left] at (-3.20, 0) {\footnotesize label4};
\end{tikzpicture}

When compiling, I got the following error:

"! Package tikz Error: A node must have a (possibly empty) label text"

Is there another error free way of labeling?

Best Answer

You need to give a label text to a node, an empty one {} would be enough:

\begin{tikzpicture}
\draw (-3,0) -- (3,0) node[below] {}; % empty label text
\draw[shift={(0,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {}; % empty label text
\draw (0,-3) -- (0,3) node[left] {}; % empty label text
\draw[shift={(0,0)}] (2pt,0pt) -- (-2pt,0pt) node[left] {}; % empty label text
\node[below] at (0,-3.20) {\footnotesize label1};
\node[above] at (0,3.20) {\footnotesize label2};
\node[right] at (3.20, 0) {\footnotesize label3};
\node[left] at (-3.20, 0) {\footnotesize label4};
\end{tikzpicture}

If you just want a named position, you can simply use coordinate. In your case, nodes in the \draw commands seems unnecessary (they don't have label texts and come with no name to be referred to later), an easier way is to draw the nodes inside paths:

\begin{tikzpicture}
\draw (0,-3) node[below] {label1} -- (0,3) node[above] {label2};
\draw (-3,0) node[left] {label4} -- (3,0) node[right] {label3};
\end{tikzpicture}

enter image description here