Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1477 from AmitAronovitch/iss997_altfix

alternate fix for issue #997
  • Loading branch information...
commit 267fb6b15c81e6ee98acbd927f9eab94f5abcb65 2 parents 73ceafa + 964a854
@ianthomas23 ianthomas23 authored
View
4 lib/matplotlib/delaunay/_delaunay.cpp
@@ -289,8 +289,8 @@ static PyObject *linear_interpolate_grid(double x0, double x1, int xsteps,
if (!z) return NULL;
z_ptr = (double*)PyArray_DATA(z);
- dx = (x1 - x0) / (xsteps-1);
- dy = (y1 - y0) / (ysteps-1);
+ dx = ( xsteps==1 ? 0 : (x1 - x0) / (xsteps-1) );
+ dy = ( ysteps==1 ? 0 : (y1 - y0) / (ysteps-1) );
rowtri = 0;
for (iy=0; iy<ysteps; iy++) {
View
BIN  lib/matplotlib/tests/baseline_images/test_delaunay/delaunay-1d-interp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
27 lib/matplotlib/tests/test_delaunay.py
@@ -159,7 +159,7 @@ def interpolator(self, func):
z = func(self.x, self.y)
return self.tri.nn_extrapolator(z, bbox=self.xrange+self.yrange)
-def make_all_testfuncs(allfuncs=allfuncs):
+def make_all_2d_testfuncs(allfuncs=allfuncs):
def make_test(func):
filenames = [
'%s-%s' % (func.func_name, x) for x in
@@ -187,4 +187,27 @@ def reference_test():
for func in allfuncs:
globals()['test_%s' % func.func_name] = make_test(func)
-make_all_testfuncs()
+make_all_2d_testfuncs()
+
+# 1d and 0d grid tests
+
+ref_interpolator = Triangulation([0,10,10,0],
+ [0,0,10,10]).linear_interpolator([1,10,5,2.0])
+
+def test_1d_grid():
+ res = ref_interpolator[3:6:2j,1:1:1j]
+ assert np.allclose(res, [[1.6],[1.9]], rtol=0)
+
+def test_0d_grid():
+ res = ref_interpolator[3:3:1j,1:1:1j]
+ assert np.allclose(res, [[1.6]], rtol=0)
+
+@image_comparison(baseline_images=['delaunay-1d-interp'], extensions=['png'])
+def test_1d_plots():
+ x_range = slice(0.25,9.75,20j)
+ x = np.mgrid[x_range]
+ ax = plt.gca()
+ for y in xrange(2,10,2):
+ plt.plot(x, ref_interpolator[x_range,y:y:1j])
+ ax.set_xticks([])
+ ax.set_yticks([])
Please sign in to comment.
Something went wrong with that request. Please try again.