2

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}
  \addplot[mark=*,color=red] coordinates {(0.1,0.1) (0.9,0.9)};
  \addplot[mark=*,color=black] coordinates {(0.1,0.09) (0.9,0.91)};
\end{axis}

\end{tikzpicture}
\end{document} 

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

enter image description here

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

  • 1
    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
3

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]
  \addplot[mark=*,color=red] coordinates {(0.1,0.1) (0.9,0.9)};
  \addplot[mark=*,color=black] coordinates {(0.1,0.09) (0.9,0.91)};
\end{axis}
\begin{axis}[clip mode=individual]
  \addplot[mark=*,color=red] coordinates {(0.1,0.1) (0.9,0.9)};
  \addplot[mark=*,color=black] coordinates {(0.1,0.09) (0.9,0.91)};
\end{axis}

\end{tikzpicture}
\end{document} 

enter image description here

Notice that I would have thought that mark layer=like plot does the trick, but this does not seem to be the case.

| improve this answer | |
  • 1
    Thanks for the quick solution, which does exactly what I want. (Reading the corresponding section in the manual was useful, though I have to say that I find it counterintuitive that a change to the clipping mode would fix this problem - after all, we don't really clip anything.) – user1362373 Feb 25 at 6:39
  • 1
    @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

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.