22
22
23
23
def streamplot (axes , x , y , u , v , density = 1 , linewidth = None , color = None ,
24
24
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 ):
26
27
"""Draws streamlines of a vector flow.
27
28
28
29
*x*, *y* : 1d arrays
@@ -53,6 +54,8 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
53
54
See :class:`~matplotlib.patches.FancyArrowPatch`.
54
55
*minlength* : float
55
56
Minimum length of streamline in axes coordinates.
57
+ *maxlength* : float
58
+ Maximum length of streamline in axes coordinates.
56
59
*start_points*: Nx2 array
57
60
Coordinates of starting points for the streamlines.
58
61
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,
126
129
u = np .ma .masked_invalid (u )
127
130
v = np .ma .masked_invalid (v )
128
131
129
- integrate = get_integrator (u , v , dmap , minlength )
132
+ integrate = get_integrator (u , v , dmap , minlength , maxlength )
130
133
131
134
trajectories = []
132
135
if start_points is None :
@@ -401,7 +404,7 @@ class TerminateTrajectory(Exception):
401
404
# Integrator definitions
402
405
#========================
403
406
404
- def get_integrator (u , v , dmap , minlength ):
407
+ def get_integrator (u , v , dmap , minlength , maxlength ):
405
408
406
409
# rescale velocity onto grid-coordinates for integrations.
407
410
u , v = dmap .data2grid (u , v )
@@ -439,9 +442,9 @@ def integrate(x0, y0):
439
442
dmap .start_trajectory (x0 , y0 )
440
443
except InvalidIndexError :
441
444
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 )
443
446
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 )
445
448
# combine forward and backward trajectories
446
449
stotal = sf + sb
447
450
x_traj = xb_traj [::- 1 ] + xf_traj [1 :]
@@ -456,7 +459,7 @@ def integrate(x0, y0):
456
459
return integrate
457
460
458
461
459
- def _integrate_rk12 (x0 , y0 , dmap , f ):
462
+ def _integrate_rk12 (x0 , y0 , dmap , f , maxlength ):
460
463
"""2nd-order Runge-Kutta algorithm with adaptive step size.
461
464
462
465
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):
532
535
dmap .update_trajectory (xi , yi )
533
536
except InvalidIndexError :
534
537
break
535
- if (stotal + ds ) > 2 :
538
+ if (stotal + ds ) > maxlength :
536
539
break
537
540
stotal += ds
538
541
0 commit comments