Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b14d46d

Browse files
author
Manuel Jung
committed
Add maximum streamline length property.
1 parent 258dbf5 commit b14d46d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/matplotlib/streamplot.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
2424
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
25-
minlength=0.1, transform=None, zorder=None, start_points=None):
25+
minlength=0.1, maxlength=2.0, transform=None, zorder=None,
26+
start_points=None):
2627
"""Draws streamlines of a vector flow.
2728
2829
*x*, *y* : 1d arrays
@@ -53,6 +54,8 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
5354
See :class:`~matplotlib.patches.FancyArrowPatch`.
5455
*minlength* : float
5556
Minimum length of streamline in axes coordinates.
57+
*maxlength* : float
58+
Maximum length of streamline in axes coordinates.
5659
*start_points*: Nx2 array
5760
Coordinates of starting points for the streamlines.
5861
In data coordinates, the same as the ``x`` and ``y`` arrays.
@@ -126,7 +129,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
126129
u = np.ma.masked_invalid(u)
127130
v = np.ma.masked_invalid(v)
128131

129-
integrate = get_integrator(u, v, dmap, minlength)
132+
integrate = get_integrator(u, v, dmap, minlength, maxlength)
130133

131134
trajectories = []
132135
if start_points is None:
@@ -401,7 +404,7 @@ class TerminateTrajectory(Exception):
401404
# Integrator definitions
402405
#========================
403406

404-
def get_integrator(u, v, dmap, minlength):
407+
def get_integrator(u, v, dmap, minlength, maxlength):
405408

406409
# rescale velocity onto grid-coordinates for integrations.
407410
u, v = dmap.data2grid(u, v)
@@ -439,9 +442,9 @@ def integrate(x0, y0):
439442
dmap.start_trajectory(x0, y0)
440443
except InvalidIndexError:
441444
return None
442-
sf, xf_traj, yf_traj = _integrate_rk12(x0, y0, dmap, forward_time)
445+
sf, xf_traj, yf_traj = _integrate_rk12(x0, y0, dmap, forward_time, maxlength)
443446
dmap.reset_start_point(x0, y0)
444-
sb, xb_traj, yb_traj = _integrate_rk12(x0, y0, dmap, backward_time)
447+
sb, xb_traj, yb_traj = _integrate_rk12(x0, y0, dmap, backward_time, maxlength)
445448
# combine forward and backward trajectories
446449
stotal = sf + sb
447450
x_traj = xb_traj[::-1] + xf_traj[1:]
@@ -456,7 +459,7 @@ def integrate(x0, y0):
456459
return integrate
457460

458461

459-
def _integrate_rk12(x0, y0, dmap, f):
462+
def _integrate_rk12(x0, y0, dmap, f, maxlength):
460463
"""2nd-order Runge-Kutta algorithm with adaptive step size.
461464
462465
This method is also referred to as the improved Euler's method, or Heun's
@@ -532,7 +535,7 @@ def _integrate_rk12(x0, y0, dmap, f):
532535
dmap.update_trajectory(xi, yi)
533536
except InvalidIndexError:
534537
break
535-
if (stotal + ds) > 2:
538+
if (stotal + ds) > maxlength:
536539
break
537540
stotal += ds
538541

0 commit comments

Comments
 (0)