plot: Don't loop forever if the function returns a NaN