pgfplots: frame not closed for surface plot

If you compile this MWE you will find that the frame for the 2d plot is closed, but for the contour plot, which is a 3d plot, not. Both figures are taken from the examples from the pgfplots manual. How can I fix this?

\documentclass[
10pt
]{scrreprt}

\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}

\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xlabel=Cost,
ylabel=Error
]
\addplot[
color=red,mark=x
] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
title={$x \exp(-x^2-y^2)$},
xlabel=$x$,
ylabel=$y$,
small,
view={0}{90},
width=10cm,
height=5cm
]
\addplot3[
surf,
%        shader=interp,
domain=-2:2,
domain y=-1.3:1.3,
]{exp(-x^2-y^2)*x};

\end{axis}
\end{tikzpicture}

\end{document}


1 Answer

This is because you are actually seeing a 3D box from above and not actually drawing a true 2D box. Hence the drawing order makes the line cornering different.

You can enforce a workaround via extending the axis lines by adding

axis line style = {shorten <=-0.5\pgflinewidth,shorten >=-0.5\pgflinewidth}


to the 3D plot axis options and that would look like a closed box.