Skip to content

Commit 9023040

Browse files
committed
Connect stream lines if no varying width or color
Streamplot segments stream lines into small pieces of lines in order to have different width and colors from each other. However, by doing the segmentation the connection of lines are getting lost. The loss of connection introduces visible gaps. This commit avoids unnecessary segmentation of a streamline into smaller lines if there is no need to do so. Fixing the problem only for non-varying width and color stream plots.
1 parent f2100d5 commit 9023040

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/streamplot.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,13 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
198198
tx += grid.x_origin
199199
ty += grid.y_origin
200200

201-
points = np.transpose([tx, ty]).reshape(-1, 1, 2)
202-
streamlines.extend(np.hstack([points[:-1], points[1:]]))
201+
# Create multiple tiny segments if varying width or color is given
202+
if isinstance(linewidth, np.ndarray) or use_multicolor_lines:
203+
points = np.transpose([tx, ty]).reshape(-1, 1, 2)
204+
streamlines.extend(np.hstack([points[:-1], points[1:]]))
205+
else:
206+
points = np.transpose([tx, ty])
207+
streamlines.append(points)
203208

204209
# Add arrows halfway along each trajectory.
205210
s = np.cumsum(np.hypot(np.diff(tx), np.diff(ty)))

0 commit comments

Comments
 (0)