0

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: enter image description here

I want this: enter image description here

\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}
4
  • You can draw the circle out of axis but using cs coordinates.
    – Sigur
    Jun 20 at 14:59
  • hmm how? @Sigur
    – Pitaya88
    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
    – Pitaya88
    Jun 20 at 15:16

2 Answers 2

3

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}

enter image description here

2
  • 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
  • 1
    @hpekristiansen Seems set layers=axis on top works. Jun 20 at 16:10
0

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);

enter image description here

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}
2
  • is not working:(
    – Pitaya88
    Jun 20 at 15:21
  • @Pitaya88, see the MWE above.
    – Sigur
    Jun 20 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.