Skip to content

Commit 4b0084a

Browse files
committed
DOC: Use dict.items to iterate subplot_mosaic result
1 parent 75441ce commit 4b0084a

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

galleries/users_explain/axes/arranging_axes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ def annotate_axes(ax, text, fontsize=18):
152152
fig, axd = plt.subplot_mosaic([['upper left', 'upper right'],
153153
['lower left', 'lower right']],
154154
figsize=(5.5, 3.5), layout="constrained")
155-
for k in axd:
156-
annotate_axes(axd[k], f'axd["{k}"]', fontsize=14)
155+
for k, ax in axd.items():
156+
annotate_axes(ax, f'axd[{k!r}]', fontsize=14)
157157
fig.suptitle('plt.subplot_mosaic()')
158158

159159
# %%
@@ -200,8 +200,8 @@ def annotate_axes(ax, text, fontsize=18):
200200
fig, axd = plt.subplot_mosaic([['upper left', 'right'],
201201
['lower left', 'right']],
202202
figsize=(5.5, 3.5), layout="constrained")
203-
for k in axd:
204-
annotate_axes(axd[k], f'axd["{k}"]', fontsize=14)
203+
for k, ax in axd.items():
204+
annotate_axes(ax, f'axd[{k!r}]', fontsize=14)
205205
fig.suptitle('plt.subplot_mosaic()')
206206

207207
# %%
@@ -223,8 +223,8 @@ def annotate_axes(ax, text, fontsize=18):
223223
['lower left', 'right']],
224224
gridspec_kw=gs_kw, figsize=(5.5, 3.5),
225225
layout="constrained")
226-
for k in axd:
227-
annotate_axes(axd[k], f'axd["{k}"]', fontsize=14)
226+
for k, ax in axd.items():
227+
annotate_axes(ax, f'axd[{k!r}]', fontsize=14)
228228
fig.suptitle('plt.subplot_mosaic()')
229229

230230
# %%
@@ -262,8 +262,8 @@ def annotate_axes(ax, text, fontsize=18):
262262
['lower left', 'lower right']]
263263

264264
fig, axd = plt.subplot_mosaic(outer, layout="constrained")
265-
for k in axd:
266-
annotate_axes(axd[k], f'axd["{k}"]')
265+
for k, ax in axd.items():
266+
annotate_axes(ax, f'axd[{k!r}]')
267267

268268
# %%
269269
# Low-level and advanced grid methods

galleries/users_explain/axes/axes_scales.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,23 @@
9898
# %%
9999
#
100100

101-
todo = ['asinh', 'symlog', 'log', 'logit', ]
102101
fig, axs = plt.subplot_mosaic([['asinh', 'symlog'],
103102
['log', 'logit']], layout='constrained')
104103

105104
x = np.arange(0, 1000)
106105

107-
for td in todo:
108-
ax = axs[td]
109-
if td in ['asinh', 'symlog']:
106+
for name, ax in axs.items():
107+
if name in ['asinh', 'symlog']:
110108
yy = x - np.mean(x)
111-
elif td in ['logit']:
109+
elif name in ['logit']:
112110
yy = (x-np.min(x))
113111
yy = yy / np.max(np.abs(yy))
114112
else:
115113
yy = x
116114

117115
ax.plot(yy, yy)
118-
ax.set_yscale(td)
119-
ax.set_title(td)
116+
ax.set_yscale(name)
117+
ax.set_title(name)
120118

121119
# %%
122120
# Optional arguments for scales
@@ -131,9 +129,8 @@
131129
fig, axs = plt.subplot_mosaic([['log', 'symlog']], layout='constrained',
132130
figsize=(6.4, 3))
133131

134-
for td in axs:
135-
ax = axs[td]
136-
if td in ['log']:
132+
for name, ax in axs.items():
133+
if name in ['log']:
137134
ax.plot(x, x)
138135
ax.set_yscale('log', base=2)
139136
ax.set_title('log base=2')

galleries/users_explain/figure/figure_intro.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ More complex grids can be achieved with `.pyplot.subplot_mosaic` (which wraps
139139

140140
fig, axs = plt.subplot_mosaic([['A', 'right'], ['B', 'right']],
141141
figsize=(4, 3), layout='constrained')
142-
for ax_name in axs:
143-
axs[ax_name].text(0.5, 0.5, ax_name, ha='center', va='center')
142+
for ax_name, ax in axs.items():
143+
ax.text(0.5, 0.5, ax_name, ha='center', va='center')
144144

145145
Sometimes we want to have a nested layout in a Figure, with two or more sets of
146146
Axes that do not share the same subplot grid.

0 commit comments

Comments
 (0)