# Line in front of marks

I am creating plots that contain a LOT of data points, and each plot also includes a line that is independent but coincident with those points.

The problem is that the marks get in front of the line, so in regions of the plot where there are too many marks the line is not clearly visible. The following MWE contais a plot with fewer points and another with a lot of points to illustrate this.

\documentclass[12pt]{article}

\usepackage{pgfplots}

\pgfplotscreateplotcyclelist{marks}{%
{black!50,ultra thin,mark=o,only marks},
{black,very thick,mark=none},
{blue!70!black!50,mark=square,only marks},
{blue!70!black,very thick,mark=none},
{red!70!black!50,mark=triangle,only marks},
{red!70!black,very thick,mark=none},
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[legend entries={0,...,6},
legend pos=outer north east,
cycle list name=marks]
\end{axis}
\end{tikzpicture}

\end{document}


With this result:

I have tried putting the line plots before the scatter plots but that didn't work. How can I make the line to be clearly visible, in front of the marks?

-

This is similar to error bars with pgfplots in foreground: By default, all the markers are drawn in one layer on top of the plots. This is done so clipping for them can be switched on or off independently from the normal clipping. You can tell PGFPlots to use an individual layer for each set of markers, instead of putting them all on the same topmost layer, by setting clip mode=individual. This means that later plots will be drawn on top of the preceding markers.

\documentclass[12pt]{article}

\usepackage{pgfplots}

\pgfplotscreateplotcyclelist{marks}{%
{black!50,ultra thin,mark=o,only marks},
{black,very thick,mark=none},
{blue!70!black!50,mark=square,only marks},
{blue!70!black,very thick,mark=none},
{red!70!black!50,mark=triangle,only marks},
{red!70!black,very thick,mark=none},
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
clip mode=individual,
legend entries={0,...,6},
legend pos=outer north east,
cycle list name=marks]

Thank you @Jake, it sounds like a great solution, but pdflatex is return an error: Package pgfkeys Error: I do not know the key '/tikz/clip mode'. I cannot find what library that option is implemented in. –  Francisco Nov 28 '12 at 15:51
@Francisco: Ah yes, that option was only implemented in a reasonably recent version of PGFPlots. I'd recommend you update your PGFPlots package. Alternatively, you can set clip=false instead of clip mode, which will work in this case, but you'll run into problems if you want to adjust your axis limits to ignore some of your data, as they will no longer be clipped. –  Jake Nov 28 '12 at 15:54
Still not working. clip=false produces no changes, and neither does clip marker paths=false. –  Francisco Nov 28 '12 at 16:20
I'm still using the older version of PGFPlots coming with TeXlive 2012, and what did work for me was actually clip marker paths=true. Hope it helps someone. –  marad Aug 6 '14 at 11:50