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

Skip to content

Add maximum streamline length property. #6062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 21, 2016
Next Next commit
Add maximum streamline length property.
  • Loading branch information
Manuel Jung committed Nov 21, 2016
commit b14d46d3de25fa3ffcfca21a897030f4f15cf84d
17 changes: 10 additions & 7 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
minlength=0.1, transform=None, zorder=None, start_points=None):
minlength=0.1, maxlength=2.0, transform=None, zorder=None,
start_points=None):
"""Draws streamlines of a vector flow.

*x*, *y* : 1d arrays
Expand Down Expand Up @@ -53,6 +54,8 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
See :class:`~matplotlib.patches.FancyArrowPatch`.
*minlength* : float
Minimum length of streamline in axes coordinates.
*maxlength* : float
Maximum length of streamline in axes coordinates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you re-arrange the docstrings too?

*start_points*: Nx2 array
Coordinates of starting points for the streamlines.
In data coordinates, the same as the ``x`` and ``y`` arrays.
Expand Down Expand Up @@ -126,7 +129,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
u = np.ma.masked_invalid(u)
v = np.ma.masked_invalid(v)

integrate = get_integrator(u, v, dmap, minlength)
integrate = get_integrator(u, v, dmap, minlength, maxlength)

trajectories = []
if start_points is None:
Expand Down Expand Up @@ -401,7 +404,7 @@ class TerminateTrajectory(Exception):
# Integrator definitions
#========================

def get_integrator(u, v, dmap, minlength):
def get_integrator(u, v, dmap, minlength, maxlength):

# rescale velocity onto grid-coordinates for integrations.
u, v = dmap.data2grid(u, v)
Expand Down Expand Up @@ -439,9 +442,9 @@ def integrate(x0, y0):
dmap.start_trajectory(x0, y0)
except InvalidIndexError:
return None
sf, xf_traj, yf_traj = _integrate_rk12(x0, y0, dmap, forward_time)
sf, xf_traj, yf_traj = _integrate_rk12(x0, y0, dmap, forward_time, maxlength)
dmap.reset_start_point(x0, y0)
sb, xb_traj, yb_traj = _integrate_rk12(x0, y0, dmap, backward_time)
sb, xb_traj, yb_traj = _integrate_rk12(x0, y0, dmap, backward_time, maxlength)
# combine forward and backward trajectories
stotal = sf + sb
x_traj = xb_traj[::-1] + xf_traj[1:]
Expand All @@ -456,7 +459,7 @@ def integrate(x0, y0):
return integrate


def _integrate_rk12(x0, y0, dmap, f):
def _integrate_rk12(x0, y0, dmap, f, maxlength):
"""2nd-order Runge-Kutta algorithm with adaptive step size.

This method is also referred to as the improved Euler's method, or Heun's
Expand Down Expand Up @@ -532,7 +535,7 @@ def _integrate_rk12(x0, y0, dmap, f):
dmap.update_trajectory(xi, yi)
except InvalidIndexError:
break
if (stotal + ds) > 2:
if (stotal + ds) > maxlength:
break
stotal += ds

Expand Down