8000 Use subfigures for text rotation demo · matplotlib/matplotlib@6e77d8e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e77d8e

Browse files
committed
Use subfigures for text rotation demo
1 parent 59c170b commit 6e77d8e

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

examples/text_labels_and_annotations/demo_text_rotation_mode.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,14 @@
2020
"""
2121

2222
import matplotlib.pyplot as plt
23-
import numpy as np
2423

2524

26-
def test_rotation_mode(fig, mode, subplot_location):
25+
def test_rotation_mode(fig, mode):
2726
ha_list = ["left", "center", "right"]
2827
va_list = ["top", "center", "baseline", "bottom"]
29-
axs = np.empty((len(va_list), len(ha_list)), object)
30-
gs = subplot_location.subgridspec(*axs.shape, hspace=0, wspace=0)
31-
axs[0, 0] = fig.add_subplot(gs[0, 0])
32-
for i in range(len(va_list)):
33-
for j in range(len(ha_list)):
34-
if (i, j) == (0, 0):
35-
continue # Already set.
36-
axs[i, j] = fig.add_subplot(
37-
gs[i, j], sharex=axs[0, 0], sharey=axs[0, 0])
38-
for ax in axs.flat:
39-
ax.set(aspect=1)
28+
axs = fig.subplots(len(va_list), len(ha_list), sharex=True, sharey=True,
29+
subplot_kw=dict(aspect=1),
30+
gridspec_kw=dict(hspace=0, wspace=0))
4031

4132
# labels and title
4233
for ha, ax in zip(ha_list, axs[-1, :]):
@@ -79,9 +70,9 @@ def test_rotation_mode(fig, mode, subplot_location):
7970

8071

8172
fig = plt.figure(figsize=(8, 5))
82-
gs = fig.add_gridspec(1, 2)
83-
test_rotation_mode(fig, "default", gs[0])
84-
test_rotation_mode(fig, "anchor", gs[1])
73+
subfigs = fig.subfigures(1, 2)
74+
test_rotation_mode(subfigs[0], "default")
75+
test_rotation_mode(subfigs[1], "anchor")
8576
plt.show()
8677

8778

0 commit comments

Comments
 (0)
0