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

Skip to content

Commit 5a27f80

Browse files
author
muahah
committed
Add some tests to prevent invalid starting points
Raise an explicit error when specified starting points are outside of the data boundaries.
1 parent 71b9ae8 commit 5a27f80

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/matplotlib/streamplot.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,18 @@ 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()
140148
sp2[:, 0] -= grid.x_origin
141149
sp2[:, 1] -= grid.y_origin
142150

0 commit comments

Comments
 (0)