Skip to content

Commit cfa709d

Browse files
committed
replace add_gridspec with plt.subplots
1 parent c44d32b commit cfa709d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

scripts/extents.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717

1818
Z = np.arange(5*5).reshape(5, 5)
1919

20-
fig = plt.figure(figsize=(8, 5))
21-
gs = fig.add_gridspec(2, 2)
20+
(fig, axs) = plt.subplots(figsize=(8, 5), nrows=2, ncols=2)
2221

23-
ax = fig.add_subplot(gs[0, 0])
22+
ax = axs[0, 0]
2423
ax.imshow(Z, extent=[0, 10, 0, 5], interpolation="nearest", origin="upper")
2524
ax.set_xlim(-1, 11), ax.set_xticks([])
2625
ax.set_ylim(-1, 6), ax.set_yticks([0, 5])
@@ -31,7 +30,7 @@
3130
ax.text(5.0, -0.5, "extent=[0,10,0,5]",
3231
ha="center", va="center", color="black", size="large")
3332

34-
ax = fig.add_subplot(gs[1, 0])
33+
ax = axs[1, 0]
3534
ax.imshow(Z, extent=[0, 10, 0, 5], interpolation="nearest", origin="lower")
3635
ax.set_xlim(-1, 11), ax.set_xticks([0, 10])
3736
ax.set_ylim(-1, 6), ax.set_yticks([0, 5])
@@ -43,7 +42,7 @@
4342
ax.text(5.0, -0.5, "extent=[0,10,0,5]",
4443
ha="center", va="center", color="black", size="large")
4544

46-
ax = fig.add_subplot(gs[1, 1])
45+
ax = axs[1, 1]
4746
ax.imshow(Z, extent=[10, 0, 0, 5], interpolation="nearest", origin="lower")
4847
ax.set_xlim(-1, 11), ax.set_xticks([0, 10])
4948
ax.set_ylim(-1, 6), ax.set_yticks([])
@@ -54,7 +53,7 @@
5453
ax.text(5.0, -0.5, "extent=[10,0,0,5]",
5554
ha="center", va="center", color="black", size="large")
5655

57-
ax = fig.add_subplot(gs[0, 1])
56+
ax = axs[0, 1]
5857
ax.imshow(Z, extent=[10, 0, 0, 5], interpolation="nearest", origin="upper")
5958
ax.set_xlim(-1, 11), ax.set_xticks([])
6059
ax.set_ylim(-1, 6), ax.set_yticks([])

0 commit comments

Comments
 (0)