# pgfplots: “incorrect” overlap of symbols and lines

I just noticed that pgfplots appears to first draw all the lines, then all the symbols. Consider this MWE:

\documentclass[10pt]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}

\begin{axis}
\end{axis}

\end{tikzpicture}
\end{document}


Here's a close-up of part of the output:

Looking at other parts of the output makes clear that the draw order is:

1. Red line
2. Black line
3. Red symbols
4. Black symbols

which seems "incorrect" to me. Yes, I admit that I should worry about more important things, but how can I get pgfplots to first draw all black items and then all red items (or vice versa)?

• Almost impossible. It probably has something to do with the internal drawing routine. I wouldn't do it with 500 bounty. After all, the node-flavor elements are supposed to cover line elements. BTW, good MWE. – Symbol 1 Feb 24 at 22:21

According to what I find clip mode=individual does the trick here.

\documentclass[tikz,10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xshift=-8cm]
\end{axis}
\begin{axis}[clip mode=individual]

Notice that I would have thought that mark layer=like plot does the trick, but this does not seem to be the case.
• @user1362373 I agree. From the description one may take that mark layer=like plot should do that. – user194703 Feb 25 at 6:43
• I suppose that this happens because when clip mode is individual, pgfplots has to install and remove the clip for each addplot command --- that will end a path and so force the drawing of the nodes associated with it. I suppose that without it the set of addplots are drawn as a single path... – Rmano Feb 25 at 9:35