8000 Add multiple arrows example · matplotlib/matplotlib@ab7c486 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab7c486

Browse files
committed
Add multiple arrows example
1 parent 3cf7cbc commit ab7c486

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

galleries/examples/images_contours_and_fields/plot_streamplot.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
V = 1 + X - Y**2
2424
speed = np.sqrt(U**2 + V**2)
2525

26-
fig, axs = plt.subplots(3, 2, figsize=(7, 9), height_ratios=[1, 1, 2])
26+
fig, axs = plt.subplots(4, 2, figsize=(7, 12), height_ratios=[1, 1, 1, 2])
2727
axs = axs.flat
2828

2929
# Varying density along a streamline
@@ -52,21 +52,27 @@
5252
axs[3].plot(seed_points[0], seed_points[1], 'bo')
5353
axs[3].set(xlim=(-w, w), ylim=(-w, w))
5454

55+
# Adding more than one arrow to each streamline
56+
axs[4].streamplot(X, Y, U, V, numarrows=3)
57+
axs[4].set_title('Multiple arrows')
58+
59+
axs[5].axis("off")
60+
5561
# Create a mask
5662
mask = np.zeros(U.shape, dtype=bool)
5763
mask[40:60, 40:60] = True
5864
U[:20, :20] = np.nan
5965
U = np.ma.array(U, mask=mask)
6066

61-
axs[4].streamplot(X, Y, U, V, color='r')
62-
axs[4].set_title('Streamplot with Masking')
67+
axs[6].streamplot(X, Y, U, V, color='r')
68+
axs[6].set_title('Streamplot with Masking')
6369

64-
axs[4].imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, cmap='gray',
70+
axs[6].imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, cmap='gray',
6571
aspect='auto')
66-
axs[4].set_aspect('equal')
72+
axs[6].set_aspect('equal')
6773

68-
axs[5].streamplot(X, Y, U, V, broken_streamlines=False)
69-
axs[5].set_title('Streamplot with unbroken streamlines')
74+
axs[7].streamplot(X, Y, U, V, broken_streamlines=False)
75+
axs[7].set_title('Streamplot with unbroken streamlines')
7076

7177
plt.tight_layout()
7278
plt.show()

0 commit comments

Comments
 (0)
0