Bring the object forward

I want to bring the white dot in front of the axis. How can I do this without removing the "axis on top" code?

current:

I want this:

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both,ymin=-5,ymax=5,xmax=5,xmin=-5,xticklabel=\empty,yticklabel=\empty,axis on top,
minor tick num=1,axis lines = middle,xlabel=$x$,ylabel=$y$,label style =
{at={(ticklabel cs:1.1)}}]
\draw[fill=white,thick] (0,3.4) circle (1.6pt);
\end{axis}
\end{tikzpicture}
\end{document}

• You can draw the circle out of axis but using cs coordinates. Jun 20 at 14:59
• hmm how? @Sigur Jun 20 at 15:00
• It's caused by option axis on top. Do you really need this option? Jun 20 at 15:09
• yes @muzimuzhiZ Jun 20 at 15:16

Option axis on top makes axis staff to be drawn on top of "main plotting" (unofficial name). It seems you can set layered graphics by set layers=axis on top and then put your drawing on a most foreground layer, which is axis foreground when axis on top is set.

See more info in pgfplots's package manual, doc for set layers and /pgfplots/layers/axis on top.

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both,ymin=-5,ymax=5,xmax=5,xmin=-5,xticklabel=\empty,yticklabel=\empty,
minor tick num=1,axis lines = middle,xlabel=$x$,ylabel=$y$,label style =
{at={(ticklabel cs:1.1)}},
set layers=axis on top]
\addplot expression {x};   % to check axis IS on top of plotting
\addplot expression {3.5}; % and \draw is on top of of axis
\begin{pgfonlayer}{axis foreground}
\draw[fill=white,thick] (0,3.4) circle (1.6pt);
\end{pgfonlayer}
\end{axis}
\end{tikzpicture}
\end{document}


• set layers (the same as set layers=default) sets the default order of layers. OP want to have the axis on top order. I am having trouble making it work. Jun 20 at 16:03
• @hpekristiansen Seems set layers=axis on top works. Jun 20 at 16:10

In the axis you can save the position:

\coordinate (foo) at (axis cs:0,3.4);


Then, out of axis you can draw anything you want on that position. For example:

\draw[fill=white,thick] (foo) circle (1.6pt);


MWE

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both,ymin=-5,ymax=5,xmax=5,xmin=-5,xticklabel=\empty,yticklabel=\empty,axis on top,
minor tick num=1,axis lines = middle,xlabel=$x$,ylabel=$y$,label style =
{at={(ticklabel cs:1.1)}}]
\coordinate (foo) at (axis cs:0,3.4);
\end{axis}
\draw[fill=white,thick] (foo) circle (1.6pt);
\end{tikzpicture}
\end{document}

• is not working:( Jun 20 at 15:21
• @Pitaya88, see the MWE above. Jun 20 at 15:32