Skip to content

Commit

Permalink
Merge pull request #6011 from muahah/master
Browse files Browse the repository at this point in the history
Fix #6003
  • Loading branch information
tacaswell committed Mar 20, 2016
2 parents 0003470 + 875b936 commit 9110be0
Show file tree
Hide file tree
Showing 19 changed files with 3,657 additions and 1,919 deletions.
32 changes: 24 additions & 8 deletions lib/matplotlib/streamplot.py
Expand Up @@ -133,12 +133,21 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
if t is not None:
trajectories.append(t)
else:
sp2 = np.asanyarray(start_points, dtype=np.float).copy()

# Check if start_points are outside the data boundaries
for xs, ys in sp2:
if (xs < grid.x_origin or xs > grid.x_origin + grid.width
or ys < grid.y_origin or ys > grid.y_origin + grid.height):
raise ValueError("Starting point ({}, {}) outside of"
" data boundaries".format(xs, ys))

# Convert start_points from data to array coords
# Shift the seed points from the bottom left of the data so that
# data2grid works properly.
sp2 = np.asanyarray(start_points, dtype=np.float).copy()
sp2[:, 0] += np.abs(x[0])
sp2[:, 1] += np.abs(y[0])
sp2[:, 0] -= grid.x_origin
sp2[:, 1] -= grid.y_origin

for xs, ys in sp2:
xg, yg = dmap.data2grid(xs, ys)
t = integrate(xg, yg)
Expand All @@ -159,8 +168,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
tgx = np.array(t[0])
tgy = np.array(t[1])
# Rescale from grid-coordinates to data-coordinates.
tx = np.array(t[0]) * grid.dx + grid.x_origin
ty = np.array(t[1]) * grid.dy + grid.y_origin
tx, ty = dmap.grid2data(*np.array(t))
tx += grid.x_origin
ty += grid.y_origin

points = np.transpose([tx, ty]).reshape(-1, 1, 2)
streamlines.extend(np.hstack([points[:-1], points[1:]]))
Expand Down Expand Up @@ -243,8 +253,8 @@ def __init__(self, grid, mask):
self.x_mask2grid = 1. / self.x_grid2mask
self.y_mask2grid = 1. / self.y_grid2mask

self.x_data2grid = grid.nx / grid.width
self.y_data2grid = grid.ny / grid.height
self.x_data2grid = 1. / grid.dx
self.y_data2grid = 1. / grid.dy

def grid2mask(self, xi, yi):
"""Return nearest space in mask-coords from given grid-coords."""
Expand All @@ -257,6 +267,9 @@ def mask2grid(self, xm, ym):
def data2grid(self, xd, yd):
return xd * self.x_data2grid, yd * self.y_data2grid

def grid2data(self, xg, yg):
return xg / self.x_data2grid, yg / self.y_data2grid

def start_trajectory(self, xg, yg):
xm, ym = self.grid2mask(xg, yg)
self.mask._start_trajectory(xm, ym)
Expand Down Expand Up @@ -418,7 +431,10 @@ def integrate(x0, y0):
resulting trajectory is None if it is shorter than `minlength`.
"""

dmap.start_trajectory(x0, y0)
try:
dmap.start_trajectory(x0, y0)
except InvalidIndexError:
return None
sf, xf_traj, yf_traj = _integrate_rk12(x0, y0, dmap, forward_time)
dmap.reset_start_point(x0, y0)
sb, xb_traj, yb_traj = _integrate_rk12(x0, y0, dmap, backward_time)
Expand Down
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9110be0

Please sign in to comment.