10BC0 Add example to plot streamplot with masked values. · matplotlib/matplotlib@a98c543 · GitHub
[go: up one dir, main page]

Skip to content

Commit a98c543

Browse files
committed
Add example to plot streamplot with masked values.
1 parent 3259d0a commit a98c543

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Demonstrate the use of the `streamplot` function using a masked array
3+
and NaN values.
4+
"""
5+
import numpy as np
6+
import matplotlib.pyplot as plt
7+
8+
w = 3
9+
Y, X = np.mgrid[-w:w:100j, -w:w:100j]
10+
U = -1 - X**2 + Y
11+
V = 1 + X - Y**2
12+
speed = np.sqrt(U*U + V*V)
13+
14+
mask = np.zeros(U.shape, dtype=bool)
15+
mask[40:60, 40:60] = 1
16+
U = np.ma.array(U, mask=mask)
17+
U[:20, :20] = np.nan
18+
19+
plt.streamplot(X, Y, U, V, color='r')
20+
plt.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, interpolation='nearest')
21+
22+
plt.show()
23+

0 commit comments

Comments
 (0)
0