# pgfplots - Zero lines draw over anything else, especially node/pins

For adding zero lines to every plot produced by pgfplots, I used the code provided by percusse here. (A quick note after 2 replies were provided: this is a "global" solution. If one likes to add the zero lines to one plot only, see esdd's reply.)

The zero lines are the last item added to every axis environment so they'll get drawn over anything that was drawn before. This is a bit ugly in the case that a pin or node is next to/on the y-axis. Of course I can move some pins' positions by changing their parameters but all in all, some will have to stay near/on the y-axis so it isn't possible for all pins.

Is this possible to solve? Or would anyone have to offer some advice anyway?

## MWE

\documentclass{article}
\usepackage{pgfplots}

\tikzset{
every pin/.style={
draw=black,
fill=white
},
every pin edge/.style={
draw=black!60,
fill=white,
thick
},}

\pgfplotsset{
every axis/.append style={
%
xmajorgrids={true},
ymajorgrids={true},
xminorgrids={false},
yminorgrids={false},
%
after end axis/.code={
%   \fill[red] (axis cs:0,0) circle(5pt);
\draw[thin] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);
\draw[thin] (axis cs:0,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:0,\pgfkeysvalueof{/pgfplots/ymax});
},
},
every tick/.append style={
black,
thick
},
/pgf/number format/.cd,
use comma,
1000 sep={.},
}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\node[pin={[pin distance=0.3cm]180:{0.9} }] at (axis cs:0.9,0.9) {};
\node[pin=0:{0.9}] at (axis cs:0.9,0.9) {};
\end{axis}
\end{tikzpicture}
\end{document}

-

You can move the drawing as being the first thing to be drawn via execute at begin axis key. Hence the only modification required is

execute at begin axis={%
%   \fill[red] (axis cs:0,0) circle(5pt);
\draw[thin] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);
\draw[thin] (axis cs:0,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:0,\pgfkeysvalueof{/pgfplots/ymax});
},


then you get,

-

Here is a suggestion using the special node current axis with the anchors above origin, below origin, left of origin and right of origin:

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

\tikzset{
every pin/.style={draw=black,fill=white},
every pin edge/.style={draw=black!60,fill=white,thick},
}

\pgfplotsset{
every axis/.append style={
xmajorgrids={true},
ymajorgrids={true},
xminorgrids={false},
yminorgrids={false},
},
every tick/.append style={black,thick},
/pgf/number format/.cd,
use comma,
1000 sep={.},
}

\begin{document}
\begin{tikzpicture}
\begin{axis}
% zero lines:
\draw[thin] (current axis.above origin) -- (current axis.below origin);
\draw[thin] (current axis.left of origin) -- (current axis.right of origin);
%
\node[pin={[pin distance=0.3cm]180:{0.9} }] at (axis cs:0.9,0.9) {};
\node[pin=0:{0.9}] at (axis cs:0.9,0.9) {};
\end{axis}
\end{tikzpicture}
\end{document}


Edit: Of course this node can also be used in execute at begin axis:

\pgfplotsset{
every axis/.append style={
xmajorgrids={true},
ymajorgrids={true},
xminorgrids={false},
yminorgrids={false},clip=false,
},
execute at begin axis={%
\draw[thin] (current axis.above origin) -- (current axis.below origin);
\draw[thin] (current axis.left of origin) -- (current axis.right of origin);
},
every tick/.append style={black,thick},
/pgf/number format/.cd,
use comma,
1000 sep={.},
}

-
Not what I was looking for at all and I already know about it, but definitely something others might find interesting! I linked your post in the op. –  henry Jun 7 '14 at 13:55
You can use this node also in execute at begin axis. –  esdd Jun 7 '14 at 14:14
I see, thanks for clarifying. :) –  henry Jun 7 '14 at 14:42