Straighten out jagged contour filled pgfplot

pgfplots

I am producing a contour-filled plot of piecewise planes with pgfplots. Some regions of the space are perfectly straight lines, whereas others (top left) are giving jagged edges. I assume this has to do with how the contour mesh (or patch? I can't quite work out the difference) is formed, but I cannot figure out how to alter this to produce the desired uniformity (i.e. the straight lines like in the middle and right regions).

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\begin{document}
\begin{tikzpicture}[baseline,
                    declare function={ReLU2(\x,\y,\theta)=max(0, cos(deg(\theta))*x + sin(deg(\theta))*y - 1/3) + max(0, -cos(deg(\theta))*x + sin(deg(\theta))*y - 1/3);},%
                   ]
       \begin{axis}[xmin=-1,xmax=1,ymin=-1,ymax=1,
            xlabel=$x_1$,
            ylabel=$x_2$,
            view = {0}{90},
            colormap/viridis,
            ]
            
          \addplot3 [domain=-1:1,
              domain y = -1:1,
              samples = 50,
              samples y = 50,
              contour filled = {number=10}
              ] {ReLU2(x,y,pi/4)};    
              
       \end{axis}
\end{tikzpicture}
\end{document}

Jagged lines in top left

I have also tried to use the \pgfplotsset{contour/handler/.style={/tikz/smooth}} command to no avail.

Any help greatly appreciated!

Best Answer

Nice filled contour plot

This image:

is made from your original unmodified code. First it is compiled to a .pfd and to make an image, I use:

convert -density 500 FilledContour.pdf -resize 500 FilledContour.png 

convert is from ImageMagick: https://imagemagick.org