Skip to content

Commit e3b8377

Browse files
committed
mlab.griddata() more robust check for constant spacing
This avoids the floating point issues referenced in matplotlib#666
1 parent 2a85d16 commit e3b8377

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/matplotlib/mlab.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2615,7 +2615,10 @@ def griddata(x,y,z,xi,yi,interp='nn'):
26152615
dy = yi[1:,0]-yi[0:-1,0]
26162616
epsx = np.finfo(xi.dtype).resolution
26172617
epsy = np.finfo(yi.dtype).resolution
2618-
if dx.max()-dx.min() > epsx or dy.max()-dy.min() > epsy:
2618+
dx_mean = dx.mean()
2619+
dy_mean = dy.mean()
2620+
if (dx.max() - dx_mean > epsx or dx_mean - dx.min() > epsx or
2621+
dy.max() - dy_mean > epsy or dy_mean - dy.min() > epsy):
26192622
raise ValueError("output grid must have constant spacing"
26202623
" when using interp='linear'")
26212624
interp = tri.linear_interpolator(z)

0 commit comments

Comments
 (0)