From 5639974b67ab7e677cfbf12cb70b28a0e1b58cc3 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sat, 1 Sep 2012 17:43:51 -0400 Subject: [PATCH 1/4] BUG: Fix streamplot when velocity component is exactly zero. --- lib/matplotlib/streamplot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/streamplot.py b/lib/matplotlib/streamplot.py index a3a349a74fee..8022f7d3fc93 100644 --- a/lib/matplotlib/streamplot.py +++ b/lib/matplotlib/streamplot.py @@ -461,14 +461,14 @@ def _euler_step(xf_traj, yf_traj, dmap, f): xi = xf_traj[-1] yi = yf_traj[-1] cx, cy = f(xi, yi) - if cx > 0: - dsx = (nx - 1 - xi) / cx - else: + if cx < 0: dsx = xi / -cx - if cy > 0: - dsy = (ny - 1 - yi) / cy else: + dsx = (nx - 1 - xi) / cx + if cy < 0: dsy = yi / -cy + else: + dsy = (ny - 1 - yi) / cy ds = min(dsx, dsy) xf_traj.append(xi + cx*ds) yf_traj.append(yi + cy*ds) From 4bbd6715aef2df137da8de85cf0e4a1a25316349 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sun, 2 Sep 2012 08:42:41 -0400 Subject: [PATCH 2/4] Catch divide-by-zero in _euler_step --- lib/matplotlib/streamplot.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/streamplot.py b/lib/matplotlib/streamplot.py index 8022f7d3fc93..2c2d707787ca 100644 --- a/lib/matplotlib/streamplot.py +++ b/lib/matplotlib/streamplot.py @@ -456,16 +456,20 @@ def _integrate_rk12(x0, y0, dmap, f): def _euler_step(xf_traj, yf_traj, dmap, f): - """Simple Euler integration step.""" + """Simple Euler integration step that extends streamline to boundary.""" ny, nx = dmap.grid.shape xi = xf_traj[-1] yi = yf_traj[-1] cx, cy = f(xi, yi) - if cx < 0: + if cx == 0: + dsx = np.inf + elif cx < 0: dsx = xi / -cx else: dsx = (nx - 1 - xi) / cx - if cy < 0: + if cy == 0: + dsy = np.inf + elif cy < 0: dsy = yi / -cy else: dsy = (ny - 1 - yi) / cy From 0d7a1d1c56167446195c37f43c3dbce20ab32278 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sun, 2 Sep 2012 08:43:44 -0400 Subject: [PATCH 3/4] Catch divide-by-zero in step calculation --- lib/matplotlib/streamplot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/streamplot.py b/lib/matplotlib/streamplot.py index 2c2d707787ca..205b22a11798 100644 --- a/lib/matplotlib/streamplot.py +++ b/lib/matplotlib/streamplot.py @@ -450,7 +450,10 @@ def _integrate_rk12(x0, y0, dmap, f): stotal += ds # recalculate stepsize based on step error - ds = min(maxds, 0.85 * ds * (maxerror/error)**0.5) + if error == 0: + ds = maxds + else: + ds = min(maxds, 0.85 * ds * (maxerror/error)**0.5) return stotal, xf_traj, yf_traj From 1d4682cec318cfb909b6de5370feb7e8d0657a81 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sun, 2 Sep 2012 08:52:59 -0400 Subject: [PATCH 4/4] Prevent warning with masked array inputs --- lib/matplotlib/streamplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/streamplot.py b/lib/matplotlib/streamplot.py index 205b22a11798..43d2d79daea3 100644 --- a/lib/matplotlib/streamplot.py +++ b/lib/matplotlib/streamplot.py @@ -325,7 +325,7 @@ def get_integrator(u, v, dmap, minlength): # speed (path length) will be in axes-coordinates u_ax = u / dmap.grid.nx v_ax = v / dmap.grid.ny - speed = np.sqrt(u_ax**2 + v_ax**2) + speed = np.ma.sqrt(u_ax**2 + v_ax**2) def forward_time(xi, yi): ds_dt = interpgrid(speed, xi, yi)