Skip to content

Commit 4bbd671

Browse files
committed
Catch divide-by-zero in _euler_step
1 parent 5639974 commit 4bbd671

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/matplotlib/streamplot.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,20 @@ def _integrate_rk12(x0, y0, dmap, f):
456456

457457

458458
def _euler_step(xf_traj, yf_traj, dmap, f):
459-
"""Simple Euler integration step."""
459+
"""Simple Euler integration step that extends streamline to boundary."""
460460
ny, nx = dmap.grid.shape
461461
xi = xf_traj[-1]
462462
yi = yf_traj[-1]
463463
cx, cy = f(xi, yi)
464-
if cx < 0:
464+
if cx == 0:
465+
dsx = np.inf
466+
elif cx < 0:
465467
dsx = xi / -cx
466468
else:
467469
dsx = (nx - 1 - xi) / cx
468-
if cy < 0:
470+
if cy == 0:
471+
dsy = np.inf
472+
elif cy < 0:
469473
dsy = yi / -cy
470474
else:
471475
dsy = (ny - 1 - yi) / cy

0 commit comments

Comments
 (0)