Skip to content

Commit 267fb6b

Browse files
committed
Merge pull request matplotlib#1477 from AmitAronovitch/iss997_altfix
alternate fix for issue matplotlib#997
2 parents 73ceafa + 964a854 commit 267fb6b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/matplotlib/delaunay/_delaunay.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ static PyObject *linear_interpolate_grid(double x0, double x1, int xsteps,
289289
if (!z) return NULL;
290290
z_ptr = (double*)PyArray_DATA(z);
291291

292-
dx = (x1 - x0) / (xsteps-1);
293-
dy = (y1 - y0) / (ysteps-1);
292+
dx = ( xsteps==1 ? 0 : (x1 - x0) / (xsteps-1) );
293+
dy = ( ysteps==1 ? 0 : (y1 - y0) / (ysteps-1) );
294294

295295
rowtri = 0;
296296
for (iy=0; iy<ysteps; iy++) {
22.4 KB
Loading

lib/matplotlib/tests/test_delaunay.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def interpolator(self, func):
159159
z = func(self.x, self.y)
160160
return self.tri.nn_extrapolator(z, bbox=self.xrange+self.yrange)
161161

162-
def make_all_testfuncs(allfuncs=allfuncs):
162+
def make_all_2d_testfuncs(allfuncs=allfuncs):
163163
def make_test(func):
164164
filenames = [
165165
'%s-%s' % (func.func_name, x) for x in
@@ -187,4 +187,27 @@ def reference_test():
187187
for func in allfuncs:
188188
globals()['test_%s' % func.func_name] = make_test(func)
189189

190-
make_all_testfuncs()
190+
make_all_2d_testfuncs()
191+
192+
# 1d and 0d grid tests
193+
194+
ref_interpolator = Triangulation([0,10,10,0],
195+
[0,0,10,10]).linear_interpolator([1,10,5,2.0])
196+
197+
def test_1d_grid():
198+
res = ref_interpolator[3:6:2j,1:1:1j]
199+
assert np.allclose(res, [[1.6],[1.9]], rtol=0)
200+
201+
def test_0d_grid():
202+
res = ref_interpolator[3:3:1j,1:1:1j]
203+
assert np.allclose(res, [[1.6]], rtol=0)
204+
205+
@image_comparison(baseline_images=['delaunay-1d-interp'], extensions=['png'])
206+
def test_1d_plots():
207+
x_range = slice(0.25,9.75,20j)
208+
x = np.mgrid[x_range]
209+
ax = plt.gca()
210+
for y in xrange(2,10,2):
211+
plt.plot(x, ref_interpolator[x_range,y:y:1j])
212+
ax.set_xticks([])
213+
ax.set_yticks([])

0 commit comments

Comments
 (0)