# pgfplots with LuaLaTeX - totally different results

Here's my code:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,colormap/blackwhite}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={-60}{40}, hide axis=true, ticks=none, line join=round, line cap=round, clip=false]
\addplot3[surf, samples=51, domain=-2:2, y domain=-2:2, line width=0.2pt, fill=white, point meta=0] {x^2*y/(x^4+y^2)};
\end{axis}
\end{tikzpicture}
\end{document}


If I run this with LaTeX I get this (which is not perfect but pretty much what I want):

But I just read that pgfplots was supposed to be faster and more accurate with LuaLaTeX, so I gave it a try. This is the result:

Huh? Am I doing something wrong or is this a bug?

• I don't know what is difference but when I use compat=1.8 instead of compat=1.16, same result is obtained with LaTeX. – ferahfeza Jul 1 '19 at 21:16
• I think you need at least 1.12 to see a difference, see pgfplots manual. – Frunobulax Jul 1 '19 at 21:25
• I executed it with compat=1.8 and got it correctly as well. – Levy Jul 1 '19 at 21:29
• When using compat=1.16 and LuaTeX, pgfplots will delegate the function evalutation to the Lua backend, which works at considerably higher precision than TeX. That is when you hit the singularities. One option would be to use samples=50, domain=-2:2. Because of the even number of samples, zero will be excluded. – Henri Menke Jul 1 '19 at 22:49

{x^2*y/(x^4+y^2+1e-6)}

or set pgfplots option unbounded coords=jump (which replaces the default of unbounded coords=discard that leads to the artefact).
• +1. I wonder if you could also mention the possibility to plot ifthenelse(x==0 && y==0,0,x^2*y/(x^4+y^2)), which does not deform the plot (I know that the deformation is negligible), or to set the samples to some even number, in which (for symmetric domains) the singularity gets avoided as well. – user121799 Jul 1 '19 at 22:12