Skip to content

Commit 9b58d8e

Browse files
committed
Update plot_types barbs to show a more realistic use case
Barbs are a visualization of vector fields and usually plotted on a regular grid.
1 parent 27f7f40 commit 9b58d8e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

plot_types/arrays/barbs.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
"""
2-
===========
3-
barbs(U, V)
4-
===========
2+
================
3+
barbs(X, Y U, V)
4+
================
55
66
See `~matplotlib.axes.Axes.barbs`.
77
"""
88
import matplotlib.pyplot as plt
99
import numpy as np
1010

11-
plt.style.use('_mpl-gallery')
11+
plt.style.use('_mpl-gallery-nogrid')
1212

1313
# make data:
14-
np.random.seed(1)
15-
X = [[2, 4, 6]]
16-
Y = [[1.5, 3, 2]]
17-
U = np.zeros_like(X)
18-
V = -np.ones_like(X) * np.linspace(50, 100, 3)
14+
X, Y = np.meshgrid([1, 2, 3, 4], [1, 2, 3, 4])
15+
angle = np.pi / 180 * np.array([[15., 30, 35, 45],
16+
[25., 40, 55, 60],
17+
[35., 50, 65, 75],
18+
[45., 60, 75, 90]])
19+
amplitude = np.array([[5, 10, 25, 50],
20+
[10, 15, 30, 60],
21+
[15, 26, 50, 70],
22+
[20, 45, 80, 100]])
23+
U = amplitude * np.sin(angle)
24+
V = amplitude * np.cos(angle)
1925

2026
# plot:
2127
fig, ax = plt.subplots()
2228

23-
ax.barbs(X, Y, U, V, barbcolor="C0", flagcolor="C0", length=10, linewidth=1.5)
29+
ax.barbs(X, Y, U, V, barbcolor="C0", flagcolor="C0", length=7, linewidth=1.5)
2430

25-
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
26-
ylim=(0, 8), yticks=np.arange(1, 8))
31+
ax.set(xlim=(0, 4.5), ylim=(0, 4.5))
2732

2833
plt.show()

0 commit comments

Comments
 (0)