# Pgfplots draws majorgrid after/over axis line

It seems like pgfplots draws the grid after the axis lines. Therefore light grey grid lines appear on top of the axis lines. This is what I mean: See the light lines separating the axis lines. I guess there is some sort of "draw this after that" solution, similar to: this topic, however I was not able to achieve the desired behaviour (axis line on top).

This should be specific to all 3D plots. Is there a concise way to adress only 3D plots?

  axis lines=box,         % left, right, center, box, none
outer axis line style={line width=5pt,},
axis line on top/.style={axis on top=true,}, % doesnt work as expected


A minimal working example is

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{
outer axis line style={line width=5pt,},
grid = major,
tickwidth = 0,
width=8cm,
height=4cm,
}
\begin{document}

\begin{tikzpicture}
\begin{axis}[%
xmin=-5, xmax=5,
ymin=0,  ymax=5,
zmin=-5, zmax=0,
view={20}{20},
]
\end{axis}
\end{tikzpicture}
\end{document}


Pgfplots draws descriptions in some smart sequence which usually provides high quality.

In your case, you need set layers. The key set layers (or, equivalently, set layers=default) defines a specific layer sequence documented as follows:

A layer configuration which defines the layers axis background, axis grid, axis ticks, axis
lines, axis tick labels, main, axis descriptions, axis foreground. They are drawn in the
order of appearance.


In particlar, it draws axis lines on top of axis grid which answers your question.

It looks like this:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{
outer axis line style={line width=5pt,},
grid = major,
tickwidth = 0,
width=8cm,
height=4cm,
set layers,
}
\begin{document}

\begin{tikzpicture}
\begin{axis}[%
xmin=-5, xmax=5,
ymin=0,  ymax=5,
zmin=-5, zmax=0,
view={20}{20},
]

• Yes, pgfplots still applies the heuristics which draws items in top of each other without activating set layers. Thus, it fixes the given order only when it encounters set layers. Maybe it will become the system default in some future version. – Christian Feuersänger Dec 4 '15 at 16:10
• There is an ugly defect in the software which messes up groupplots when used together with set layers. It exists up to and including version 1.12 (the latest stable at the time of this writing). In order to work around this limitation, you can use \pgfplotsset{set layers,cell picture=true}. I have finally managed to fixed that defect (thanks to god, was hard to catch). The fix will become part of 1.13. – Christian Feuersänger Dec 4 '15 at 16:15