Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f7c391

Browse files
authored
Merge pull request #18793 from timhoffm/axs
DOC: Consistently use axs to refer to a list of Axes (v2)
2 parents 0c76f2e + 4c51a9e commit 8f7c391

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

examples/text_labels_and_annotations/legend_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
###############################################################################
6464
# Here we attach legends to more complex plots.
6565

66-
fig, axes = plt.subplots(3, 1, constrained_layout=True)
67-
top_ax, middle_ax, bottom_ax = axes
66+
fig, axs = plt.subplots(3, 1, constrained_layout=True)
67+
top_ax, middle_ax, bottom_ax = axs
6868

6969
top_ax.bar([0, 1, 2], [0.2, 0.3, 0.1], width=0.4, label="Bar 1",
7070
align="center")

lib/matplotlib/tests/test_legend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ def test_rc():
164164
def test_legend_expand():
165165
"""Test expand mode"""
166166
legend_modes = [None, "expand"]
167-
fig, axes_list = plt.subplots(len(legend_modes), 1)
167+
fig, axs = plt.subplots(len(legend_modes), 1)
168168
x = np.arange(100)
169-
for ax, mode in zip(axes_list, legend_modes):
169+
for ax, mode in zip(axs, legend_modes):
170170
ax.plot(x, 50 - x, 'o', label='y=1')
171171
l1 = ax.legend(loc='upper left', mode=mode)
172172
ax.add_artist(l1)

tutorials/colors/colormaps.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,19 @@
205205

206206

207207
def plot_color_gradients(cmap_category, cmap_list, nrows):
208-
fig, axes = plt.subplots(nrows=nrows)
208+
fig, axs = plt.subplots(nrows=nrows)
209209
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
210-
axes[0].set_title(cmap_category + ' colormaps', fontsize=14)
210+
axs[0].set_title(cmap_category + ' colormaps', fontsize=14)
211211

212-
for ax, name in zip(axes, cmap_list):
212+
for ax, name in zip(axs, cmap_list):
213213
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
214214
pos = list(ax.get_position().bounds)
215215
x_text = pos[0] - 0.01
216216
y_text = pos[1] + pos[3]/2.
217217
fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)
218218

219219
# Turn off *all* ticks & spines, not just the ones with colormaps.
220-
for ax in axes:
220+
for ax in axs:
221221
ax.set_axis_off()
222222

223223

@@ -258,10 +258,10 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
258258
nsubplots = int(np.ceil(len(cmap_list) / dsub))
259259

260260
# squeeze=False to handle similarly the case of a single subplot
261-
fig, axes = plt.subplots(nrows=nsubplots, squeeze=False,
262-
figsize=(7, 2.6*nsubplots))
261+
fig, axs = plt.subplots(nrows=nsubplots, squeeze=False,
262+
figsize=(7, 2.6*nsubplots))
263263

264-
for i, ax in enumerate(axes.flat):
264+
for i, ax in enumerate(axs.flat):
265265

266266
locs = [] # locations for text labels
267267

@@ -300,7 +300,7 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
300300
# Set up the axis limits:
301301
# * the 1st subplot is used as a reference for the x-axis limits
302302
# * lightness values goes from 0 to 100 (y-axis limits)
303-
ax.set_xlim(axes[0, 0].get_xlim())
303+
ax.set_xlim(axs[0, 0].get_xlim())
304304
ax.set_ylim(0.0, 100.0)
305305

306306
# Set up labels for colormaps
@@ -364,12 +364,12 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
364364

365365

366366
def plot_color_gradients(cmap_category, cmap_list):
367-
fig, axes = plt.subplots(nrows=len(cmap_list), ncols=2)
367+
fig, axs = plt.subplots(nrows=len(cmap_list), ncols=2)
368368
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99,
369369
wspace=0.05)
370370
fig.suptitle(cmap_category + ' colormaps', fontsize=14, y=1.0, x=0.6)
371371

372-
for ax, name in zip(axes, cmap_list):
372+
for ax, name in zip(axs, cmap_list):
373373

374374
# Get RGB values for colormap.
375375
rgb = cm.get_cmap(plt.get_cmap(name))(x)[np.newaxis, :, :3]
@@ -387,7 +387,7 @@ def plot_color_gradients(cmap_category, cmap_list):
387387
fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)
388388

389389
# Turn off *all* ticks & spines, not just the ones with colormaps.
390-
for ax in axes.flat:
390+
for ax in axs.flat:
391391
ax.set_axis_off()
392392

393393
plt.show()

0 commit comments

Comments
 (0)