|
24 | 24 |
|
25 | 25 |
|
26 | 26 | 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)) |
29 | 28 |
|
30 | 29 | # 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') |
33 | 32 |
|
34 | 33 | # 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') |
39 | 37 |
|
40 | 38 | # Varying line width along a streamline
|
41 | 39 | 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') |
44 | 42 |
|
45 | 43 | # Controlling the starting points of the streamlines
|
46 | 44 | seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]])
|
47 | 45 |
|
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') |
53 | 49 |
|
54 | 50 | # 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)) |
57 | 53 |
|
58 | 54 | # Create a mask
|
59 | 55 | mask = np.zeros(U.shape, dtype=bool)
|
60 | 56 | mask[40:60, 40:60] = True
|
61 | 57 | U[:20, :20] = np.nan
|
62 | 58 | U = np.ma.array(U, mask=mask)
|
63 | 59 |
|
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() |
67 | 63 | ax4 = fig.add_subplot(gs[2:, :])
|
68 | 64 | ax4.streamplot(X, Y, U, V, color='r')
|
69 | 65 | ax4.set_title('Streamplot with Masking')
|
|
0 commit comments