Skip to content

Connect stream lines if no varying width or color #25112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/api/next_api_changes/behavior/25112-GG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Streamplot now draws streamlines as one piece if no width or no color variance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since there is no need to draw streamlines piece by piece if there is no color
change or width change, now streamplot will draw each streamline in one piece.

The behavior for varying width or varying color is not changed, same logic is
used for these kinds of streamplots.
9 changes: 7 additions & 2 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,13 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
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:]]))
# Create multiple tiny segments if varying width or color is given
if isinstance(linewidth, np.ndarray) or use_multicolor_lines:
points = np.transpose([tx, ty]).reshape(-1, 1, 2)
streamlines.extend(np.hstack([points[:-1], points[1:]]))
else:
points = np.transpose([tx, ty])
streamlines.append(points)

# Add arrows halfway along each trajectory.
s = np.cumsum(np.hypot(np.diff(tx), np.diff(ty)))
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.