Skip to content

Commit 71b9ae8

Browse files
author
muahah
committed
Fix starting points misplacement
Fix passage from data to grid coordinates for starting points.
1 parent e9ddd00 commit 71b9ae8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/matplotlib/streamplot.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
137137
# Shift the seed points from the bottom left of the data so that
138138
# data2grid works properly.
139139
sp2 = np.asanyarray(start_points, dtype=np.float).copy()
140-
sp2[:, 0] += np.abs(x[0])
141-
sp2[:, 1] += np.abs(y[0])
140+
sp2[:, 0] -= grid.x_origin
141+
sp2[:, 1] -= grid.y_origin
142+
142143
for xs, ys in sp2:
143144
xg, yg = dmap.data2grid(xs, ys)
144145
t = integrate(xg, yg)
@@ -159,8 +160,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
159160
tgx = np.array(t[0])
160161
tgy = np.array(t[1])
161162
# 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
163+
tx, ty = dmap.grid2data(*np.array(t))
164+
tx += grid.x_origin
165+
ty += grid.y_origin
164166

165167
points = np.transpose([tx, ty]).reshape(-1, 1, 2)
166168
streamlines.extend(np.hstack([points[:-1], points[1:]]))
@@ -243,8 +245,8 @@ def __init__(self, grid, mask):
243245
self.x_mask2grid = 1. / self.x_grid2mask
244246
self.y_mask2grid = 1. / self.y_grid2mask
245247

246-
self.x_data2grid = grid.nx / grid.width
247-
self.y_data2grid = grid.ny / grid.height
248+
self.x_data2grid = 1. / grid.dx
249+
self.y_data2grid = 1. / grid.dy
248250

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

262+
def grid2data(self, xg, yg):
263+
return xg / self.x_data2grid, yg / self.y_data2grid
264+
260265
def start_trajectory(self, xg, yg):
261266
xm, ym = self.grid2mask(xg, yg)
262267
self.mask._start_trajectory(xm, ym)

0 commit comments

Comments
 (0)