# Z-Order of plots pgfplots

Simple question:

I can’t seem to control the z-order (i.e. which comes in front, which comes in the back) of the plots in a 2D axis.

MWE:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[only marks] table {
0 2
1 1
2 2
};
\addplot+[mark=none, line width=2pt] table {
0 2
1 1
2 2
};
\end{axis}
\end{tikzpicture}
\end{document}


Obligatory screenshot:

The problem here is that the first plot, only marks always comes in front of the other plot. If I reverse the order of the respective \addplot commands then the colours and marks are switched but not the order of the plots. That is, the only marks are still in front of the line.

How can I change this?

(Yes, I need two separate plots here since the line will actually be a regression curve that uses different data but there is a huge overlap and the curve is barely visible below the point cloud).

• That even ignores the pgfonlayer environment! – Caramdir Feb 12 '11 at 1:49

## 1 Answer

It works if you set the option clip marker paths:

\begin{axis}[clip marker paths=true]


That might actually be an unintended side effect of the option.

• So we may assume that it’s a bug then? Anyway, thanks. – Konrad Rudolph Feb 12 '11 at 12:00
• I think you should just ask Christian directly. Maybe he is willing to implement a documented option to control the z-order of markers. – Philipp Feb 12 '11 at 12:26
• Thanks -- adding the axis option solves the corresponding problem in matlab2tikz as well. – Andrew D. King Feb 19 '19 at 22:49