8000 Fix error raised when trajectory lands on Nx or Ny. · matplotlib/matplotlib@5632418 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5632418

Browse files
committed
Fix error raised when trajectory lands on Nx or Ny.
1 parent 3144f6d commit 5632418

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/matplotlib/streamplot.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,27 @@ def _rk45(x0, y0, dmap, f):
570570

571571
def interpgrid(a, xi, yi):
572572
"""Fast 2D, linear interpolation on an integer grid"""
573+
574+
Ny, Nx = np.shape(a)
573575
if type(xi) == np.ndarray:
574576
x = xi.astype(np.int)
575577
y = yi.astype(np.int)
578+
# Check that xn, yn don't exceed max index
579+
xn = np.clip(x + 1, 0, Nx - 1)
580+
yn = np.clip(y + 1, 0, Ny - 1)
576581
else:
577582
x = np.int(xi)
578583
y = np.int(yi)
584+
# conditional is faster than clipping for integers
585+
if x == (Nx - 2): xn = x
586+
else: xn = x + 1
587+
if y == (Ny - 2): yn = y
588+
else: yn = y + 1
589+
579590
a00 = a[y, x]
580-
a01 = a[y, x + 1]
581-
a10 = a[y + 1, x]
582-
a11 = a[y + 1, x + 1]
591+
a01 = a[y, xn]
592+
a10 = a[yn, x]
593+
a11 = a[yn, xn]
583594
xt = xi - x
584595
yt = yi - y
585596
a0 = a00 * (1 - xt) + a01 * xt

0 commit comments

Comments
 (0)
0