8000 changing the use of gridspec() to avoid repeatation, removing unpacki… · matplotlib/matplotlib@cd25cea · GitHub
[go: up one dir, main page]

Skip to content

Commit cd25cea

Browse files
committed
changing the use of gridspec() to avoid repeatation, removing unpacking and changing varibale name
1 parent 3c4faca commit cd25cea

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

examples/images_contours_and_fields/plot_streamplot.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,42 @@
2424

2525

2626
gs = {'height_ratios': [1, 1, 2]}
27-
fig, axes = plt.subplots(nrows=3, ncols=2, gridspec_kw=gs, figsize=(7, 9))
28-
((ax0, ax1), (ax2, ax3), (ax4, ax5)) = axes
27+
fig, axs = plt.subplots(nrows=3, ncols=2, gridspec_kw=gs, figsize=(7, 9))
2928

3029
# Varying density along a streamline
31-
ax0.streamplot(X, Y, U, V, density=[0.5, 1])
32-
ax0.set_title('Varying Density')
30+
axs[0, 0].streamplot(X, Y, U, V, density=[0.5, 1])
31+
axs[0, 0].set_title('Varying Density')
3332

3433
# Varying color along a streamline
35-
plt.sca(ax1)
36-
strm = ax1.streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn')
37-
fig.colorbar(strm.lines)
38-
ax1.set_title('Varying Color')
34+
strm = axs[0, 1].streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn')
35+
fig.colorbar(strm.lines, ax=axs[0, 1])
36+
axs[0, 1].set_title('Varying Color')
3937

4038
# Varying line width along a streamline
4139
lw = 5*speed / speed.max()
42-
ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw)
43-
ax2.set_title('Varying Line Width')
40+
axs[1, 0].streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw)
41+
axs[1, 0].set_title('Varying Line Width')
4442

4543
# Controlling the starting points of the streamlines
4644
seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]])
4745

48-
plt.sca(ax3)
49-
strm = ax3.streamplot(X, Y, U, V, color=U, linewidth=2,
50-
cmap='autumn', start_points=seed_points.T)
51-
fig.colorbar(strm.lines)
52-
ax3.set_title('Controlling Starting Points')
46+
strm = axs[1, 1].streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn', start_points=seed_points.T)
47+
fig.colorbar(strm.lines, ax=axs[1, 1])
48+
axs[1, 1].set_title('Controlling Starting Points')
5349

5450
# Displaying the starting points with blue symbols.
55-
ax3.plot(seed_points[0], seed_points[1], 'bo')
56-
ax3.set(xlim=(-w, w), ylim=(-w, w))
51+
axs[1, 1].plot(seed_points[0], seed_points[1], 'bo')
52+
axs[1, 1].set(xlim=(-w, w), ylim=(-w, w))
5753

5854
# Create a mask
5955
mask = np.zeros(U.shape, dtype=bool)
6056
mask[40:60, 40:60] = True
6157
U[:20, :20] = np.nan
6258
U = np.ma.array(U, mask=mask)
6359

64-
gs = gridspec.GridSpec(nrows=3, ncols=2, height_ratios=[1, 1, 2])
65-
ax4.remove()
66-
ax5.remove()
60+
gs = axs[0, 0].get_subplotspec().get_gridspec()
61+
axs[2, 0].remove()
62+
axs[2, 1].remove()
6763
ax4 = fig.add_subplot(gs[2:, :])
6864
ax4.streamplot(X, Y, U, V, color='r')
6965
ax4.set_title('Streamplot with Masking')

0 commit comments

Comments
 (0)
0