8000 Fix handling of stream line width with multiple arrows · matplotlib/matplotlib@0a5c227 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a5c227

Browse files
committed
Fix handling of stream line width with multiple arrows
1 parent 690d255 commit 0a5c227

File tree

7 files changed

+10
-3107
lines changed

7 files changed

+10
-3107
lines changed

doc/users/next_whats_new/streamplot_multiple_arrows.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ allows more than one arrow to be added to each streamline:
66

77
.. plot::
88
:include-source: true
9-
:alt: One chart showing a streamplot. Each streamline has a three arrows.
9+
:alt: One chart showing a streamplot. Each streamline has three arrows.
1010

1111
import matplotlib.pyplot as plt
1212
import numpy as np

galleries/examples/images_contours_and_fields/plot_streamplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# Varying line width along a streamline
3939
lw = 5*speed / speed.max()
40-
axs[2].streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw)
40+
axs[2].streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw, num_arrows=5)
4141
axs[2].set_title('Varying Line Width')
4242

4343
# Controlling the starting points of the streamlines

lib/matplotlib/streamplot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
216216

217217
# Distance along streamline
218218
s = np.cumsum(np.hypot(np.diff(tx), np.diff(ty)))
219+
if isinstance(linewidth, np.ndarray):
220+
line_widths = interpgrid(linewidth, tgx, tgy)[:-1]
221+
line_kw['linewidth'].extend(line_widths)
219222
if use_multicolor_lines:
220223
color_values = interpgrid(color, tgx, tgy)[:-1]
221224
line_colors.append(color_values)
@@ -228,8 +231,6 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
228231
arrow_head = (np.mean(tx[idx:idx + 2]), np.mean(ty[idx:idx + 2]))
229232

230233
if isinstance(linewidth, np.ndarray):
231-
line_widths = interpgrid(linewidth, tgx, tgy)[:-1]
232-
line_kw['linewidth'].extend(line_widths)
233234
arrow_kw['linewidth'] = line_widths[idx]
234235

235236
if use_multicolor_lines:
Binary file not shown.
Loading

0 commit comments

Comments
 (0)
0