Here's my code:

  \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)};

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

pgfplots with LaTeX

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:

pgfplots with LuaLaTeX

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

  • 2
    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
  • 1
    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
  • 3
    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

You're seeing differences in handling the unbounded (NaN) values that result from division by zero in your equation at (0, 0). Either avoid the division by zero by using for example


or set pgfplots option unbounded coords=jump (which replaces the default of unbounded coords=discard that leads to the artefact).

  • 6
    +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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.