Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9110be0

Browse filesBrowse files
committed
Merge pull request #6011 from muahah/master
Fix #6003
2 parents 0003470 + 875b936 commit 9110be0
Copy full SHA for 9110be0
Expand file treeCollapse file tree

19 files changed

+3657
-1919
lines changed

‎lib/matplotlib/streamplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/streamplot.py
+24-8Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,21 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
133133
if t is not None:
134134
trajectories.append(t)
135135
else:
136+
sp2 = np.asanyarray(start_points, dtype=np.float).copy()
137+
138+
# Check if start_points are outside the data boundaries
139+
for xs, ys in sp2:
140+
if (xs < grid.x_origin or xs > grid.x_origin + grid.width
141+
or ys < grid.y_origin or ys > grid.y_origin + grid.height):
142+
raise ValueError("Starting point ({}, {}) outside of"
143+
" data boundaries".format(xs, ys))
144+
136145
# Convert start_points from data to array coords
137146
# Shift the seed points from the bottom left of the data so that
138147
# data2grid works properly.
139-
sp2 = np.asanyarray(start_points, dtype=np.float).copy()
140-
sp2[:, 0] += np.abs(x[0])
141-
sp2[:, 1] += np.abs(y[0])
148+
sp2[:, 0] -= grid.x_origin
149+
sp2[:, 1] -= grid.y_origin
150+
142151
for xs, ys in sp2:
143152
xg, yg = dmap.data2grid(xs, ys)
144153
t = integrate(xg, yg)
@@ -159,8 +168,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
159168
tgx = np.array(t[0])
160169
tgy = np.array(t[1])
161170
# Rescale from grid-coordinates to data-coordinates.
162-
tx = np.array(t[0]) * grid.dx + grid.x_origin
163-
ty = np.array(t[1]) * grid.dy + grid.y_origin
171+
tx, ty = dmap.grid2data(*np.array(t))
172+
tx += grid.x_origin
173+
ty += grid.y_origin
164174

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

246-
self.x_data2grid = grid.nx / grid.width
247-
self.y_data2grid = grid.ny / grid.height
256+
self.x_data2grid = 1. / grid.dx
257+
self.y_data2grid = 1. / grid.dy
248258

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

270+
def grid2data(self, xg, yg):
271+
return xg / self.x_data2grid, yg / self.y_data2grid
272+
260273
def start_trajectory(self, xg, yg):
261274
xm, ym = self.grid2mask(xg, yg)
262275
self.mask._start_trajectory(xm, ym)
@@ -418,7 +431,10 @@ def integrate(x0, y0):
418431
resulting trajectory is None if it is shorter than `minlength`.
419432
"""
420433

421-
dmap.start_trajectory(x0, y0)
434+
try:
435+
dmap.start_trajectory(x0, y0)
436+
except InvalidIndexError:
437+
return None
422438
sf, xf_traj, yf_traj = _integrate_rk12(x0, y0, dmap, forward_time)
423439
dmap.reset_start_point(x0, y0)
424440
sb, xb_traj, yb_traj = _integrate_rk12(x0, y0, dmap, backward_time)
Binary file not shown.
Loading

‎lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap_test_image.svg renamed to ‎lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.svg

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.svg
+799-800Lines changed: 799 additions & 800 deletions
Loading
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.