Skip to content

Commit 30a6af3

Browse files
committed
Use Axes instead of axes core library code
Part of matplotlib#18726.
1 parent 8f296db commit 30a6af3

39 files changed

+272
-272
lines changed

lib/matplotlib/_constrained_layout.py

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
Adjust subplot layouts so that there are no overlapping axes or axes
3-
decorations. All axes decorations are dealt with (labels, ticks, titles,
2+
Adjust subplot layouts so that there are no overlapping Axes or Axes
3+
decorations. All Axes decorations are dealt with (labels, ticks, titles,
44
ticklabels) and some dependent artists are also dealt with (colorbar,
55
suptitle).
66
77
Layout is done via `~matplotlib.gridspec`, with one constraint per gridspec,
8-
so it is possible to have overlapping axes if the gridspecs overlap (i.e.
8+
so it is possible to have overlapping Axes if the gridspecs overlap (i.e.
99
using `~matplotlib.gridspec.GridSpecFromSubplotSpec`). Axes placed using
1010
``figure.subplots()`` or ``figure.add_subplots()`` will participate in the
1111
layout. Axes manually placed via ``figure.add_axes()`` will not.
@@ -33,8 +33,8 @@
3333
is the width or height of each column/row minus the size of the margins.
3434
3535
Then the size of the margins for each row and column are determined as the
36-
max width of the decorators on each axes that has decorators in that margin.
37-
For instance, a normal axes would have a left margin that includes the
36+
max width of the decorators on each Axes that has decorators in that margin.
37+
For instance, a normal Axes would have a left margin that includes the
3838
left ticklabels, and the ylabel if it exists. The right margin may include a
3939
colorbar, the bottom margin the xaxis decorations, and the top margin the
4040
title.
@@ -73,11 +73,11 @@ def do_constrained_layout(fig, h_pad, w_pad,
7373
`.Figure` instance to do the layout in.
7474
7575
h_pad, w_pad : float
76-
Padding around the axes elements in figure-normalized units.
76+
Padding around the Axes elements in figure-normalized units.
7777
7878
hspace, wspace : float
7979
Fraction of the figure to dedicate to space between the
80-
axes. These are evenly spread between the gaps between the axes.
80+
Axes. These are evenly spread between the gaps between the Axes.
8181
A value of 0.2 for a three-column layout would have a space
8282
of 0.1 of the figure width between each column.
8383
If h/wspace < h/w_pad, then the pads are used instead.
@@ -111,7 +111,7 @@ def do_constrained_layout(fig, h_pad, w_pad,
111111
# larger/smaller). This second reposition tends to be much milder,
112112
# so doing twice makes things work OK.
113113

114-
# make margins for all the axes and subfigures in the
114+
# make margins for all the Axes and subfigures in the
115115
# figure. Add margins for colorbars...
116116
make_layout_margins(layoutgrids, fig, renderer, h_pad=h_pad,
117117
w_pad=w_pad, hspace=hspace, wspace=wspace)
@@ -128,7 +128,7 @@ def do_constrained_layout(fig, h_pad, w_pad,
128128

129129
warn_collapsed = ('constrained_layout not applied because '
130130
'axes sizes collapsed to zero. Try making '
131-
'figure larger or axes decorations smaller.')
131+
'figure larger or Axes decorations smaller.')
132132
if check_no_collapsed_axes(layoutgrids, fig):
133133
reposition_axes(layoutgrids, fig, renderer, h_pad=h_pad,
134134
w_pad=w_pad, hspace=hspace, wspace=wspace)
@@ -152,7 +152,7 @@ def make_layoutgrids(fig, layoutgrids, rect=(0, 0, 1, 1)):
152152
153153
(Sub)Figures get a layoutgrid so we can have figure margins.
154154
155-
Gridspecs that are attached to axes get a layoutgrid so axes
155+
Gridspecs that are attached to Axes get a layoutgrid so Axes
156156
can have margins.
157157
"""
158158

@@ -182,7 +182,7 @@ def make_layoutgrids(fig, layoutgrids, rect=(0, 0, 1, 1)):
182182
for sfig in fig.subfigs:
183183
layoutgrids = make_layoutgrids(sfig, layoutgrids)
184184

185-
# for each axes at the local level add its gridspec:
185+
# for each Axes at the local level add its gridspec:
186186
for ax in fig._localaxes:
187187
gs = ax.get_gridspec()
188188
if gs is not None:
@@ -239,7 +239,7 @@ def make_layoutgrids_gs(layoutgrids, gs):
239239

240240
def check_no_collapsed_axes(layoutgrids, fig):
241241
"""
242-
Check that no axes have collapsed to zero size.
242+
Check that no Axes have collapsed to zero size.
243243
"""
244244
for sfig in fig.subfigs:
245245
ok = check_no_collapsed_axes(layoutgrids, sfig)
@@ -270,7 +270,7 @@ def compress_fixed_aspect(layoutgrids, fig):
270270
extraw = np.zeros(gs.ncols)
271271
extrah = np.zeros(gs.nrows)
272272
elif _gs != gs:
273-
raise ValueError('Cannot do compressed layout if axes are not'
273+
raise ValueError('Cannot do compressed layout if Axes are not'
274274
'all from the same gridspec')
275275
orig = ax.get_position(original=True)
276276
actual = ax.get_position(original=False)
@@ -282,7 +282,7 @@ def compress_fixed_aspect(layoutgrids, fig):
282282
extrah[sub.rowspan] = np.maximum(extrah[sub.rowspan], dh)
283283

284284
if gs is None:
285-
raise ValueError('Cannot do compressed layout if no axes '
285+
raise ValueError('Cannot do compressed layout if no Axes '
286286
'are part of a gridspec.')
287287
w = np.sum(extraw) / 2
288288
layoutgrids[fig].edit_margin_min('left', w)
@@ -313,7 +313,7 @@ def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,
313313
nrows, ncols = gs.get_geometry()
314314
# there are two margins for each direction. The "cb"
315315
# margins are for pads and colorbars, the non-"cb" are
316-
# for the axes decorations (labels etc).
316+
# for the Axes decorations (labels etc).
317317
margin = {'leftcb': w_pad, 'rightcb': w_pad,
318318
'bottomcb': h_pad, 'topcb': h_pad,
319319
'left': 0, 'right': 0,
@@ -335,7 +335,7 @@ def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,
335335
def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
336336
hspace=0, wspace=0):
337337
"""
338-
For each axes, make a margin between the *pos* layoutbox and the
338+
For each Axes, make a margin between the *pos* layoutbox and the
339339
*axes* layoutbox be a minimum size that can accommodate the
340340
decorations on the axis.
341341
@@ -379,7 +379,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
379379
margin = get_margin_from_padding(ax, w_pad=w_pad, h_pad=h_pad,
380380
hspace=hspace, wspace=wspace)
381381
pos, bbox = get_pos_and_bbox(ax, renderer)
382-
# the margin is the distance between the bounding box of the axes
382+
# the margin is the distance between the bounding box of the Axes
383383
# and its position (plus the padding from above)
384384
margin['left'] += pos.x0 - bbox.x0
385385
margin['right'] += bbox.x1 - pos.x1
@@ -388,7 +388,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
388388
margin['top'] += bbox.y1 - pos.y1
389389

390390
# make margin for colorbars. These margins go in the
391-
# padding margin, versus the margin for axes decorators.
391+
# padding margin, versus the margin for Axes decorators.
392392
for cbax in ax._colorbars:
393393
# note pad is a fraction of the parent width...
394394
pad = colorbar_get_pad(layoutgrids, cbax)
@@ -493,14 +493,14 @@ def match_submerged_margins(layoutgrids, fig):
493493
"""
494494
Make the margins that are submerged inside an Axes the same size.
495495
496-
This allows axes that span two columns (or rows) that are offset
496+
This allows Axes that span two columns (or rows) that are offset
497497
from one another to have the same size.
498498
499499
This gives the proper layout for something like::
500500
fig = plt.figure(constrained_layout=True)
501501
axs = fig.subplot_mosaic("AAAB\nCCDD")
502502
503-
Without this routine, the axes D will be wider than C, because the
503+
Without this routine, the Axes D will be wider than C, because the
504504
margin width between the two columns in C has no width by default,
505505
whereas the margins between the two columns of D are set by the
506506
width of the margin between A and B. However, obviously the user would
@@ -613,7 +613,7 @@ def get_cb_parent_spans(cbax):
613613

614614
def get_pos_and_bbox(ax, renderer):
615615
"""
616-
Get the position and the bbox for the axes.
616+
Get the position and the bbox for the Axes.
617617
618618
Parameters
619619
----------
@@ -642,7 +642,7 @@ def get_pos_and_bbox(ax, renderer):
642642
def reposition_axes(layoutgrids, fig, renderer, *,
643643
w_pad=0, h_pad=0, hspace=0, wspace=0):
644644
"""
645-
Reposition all the axes based on the new inner bounding box.
645+
Reposition all the Axes based on the new inner bounding box.
646646
"""
647647
trans_fig_to_subfig = fig.transFigure - fig.transSubfigure
648648
for sfig in fig.subfigs:

lib/matplotlib/_layoutgrid.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
66
Each box is defined by left[ncols], right[ncols], bottom[nrows] and top[nrows],
77
and by two editable margins for each side. The main margin gets its value
8-
set by the size of ticklabels, titles, etc on each axes that is in the figure.
9-
The outer margin is the padding around the axes, and space for any
8+
set by the size of ticklabels, titles, etc on each Axes that is in the figure.
9+
The outer margin is the padding around the Axes, and space for any
1010
colorbars.
1111
1212
The "inner" widths and heights of these boxes are then constrained to be the

lib/matplotlib/_tight_layout.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Routines to adjust subplot params so that subplots are
3-
nicely fit in the figure. In doing so, only axis labels, tick labels, axes
4-
titles and offsetboxes that are anchored to axes are currently considered.
3+
nicely fit in the figure. In doing so, only axis labels, tick labels, Axes
4+
titles and offsetboxes that are anchored to Axes are currently considered.
55
66
Internally, this module assumes that the margins (left margin, etc.) which are
77
differences between ``Axes.get_tightbbox`` and ``Axes.bbox`` are independent of
@@ -22,7 +22,7 @@ def _auto_adjust_subplotpars(
2222
ax_bbox_list=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
2323
"""
2424
Return a dict of subplot parameters to adjust spacing between subplots
25-
or ``None`` if resulting axes would have zero height or width.
25+
or ``None`` if resulting Axes would have zero height or width.
2626
2727
Note that this function ignores geometry information of subplot itself, but
2828
uses what is given by the *shape* and *subplot_list* parameters. Also, the
@@ -91,7 +91,7 @@ def _auto_adjust_subplotpars(
9191

9292
fig_width_inch, fig_height_inch = fig.get_size_inches()
9393

94-
# margins can be negative for axes with aspect applied, so use max(, 0) to
94+
# margins can be negative for Axes with aspect applied, so use max(, 0) to
9595
# make them nonnegative.
9696
if not margin_left:
9797
margin_left = max(hspaces[:, 0].max(), 0) + pad_inch/fig_width_inch
@@ -119,12 +119,12 @@ def _auto_adjust_subplotpars(
119119
if margin_left + margin_right >= 1:
120120
_api.warn_external('Tight layout not applied. The left and right '
121121
'margins cannot be made large enough to '
122-
'accommodate all axes decorations.')
122+
'accommodate all Axes decorations.')
123123
return None
124124
if margin_bottom + margin_top >= 1:
125125
_api.warn_external('Tight layout not applied. The bottom and top '
126126
'margins cannot be made large enough to '
127-
'accommodate all axes decorations.')
127+
'accommodate all Axes decorations.')
128128
return None
129129

130130
kwargs = dict(left=margin_left,
@@ -138,8 +138,8 @@ def _auto_adjust_subplotpars(
138138
h_axes = (1 - margin_right - margin_left - hspace * (cols - 1)) / cols
139139
if h_axes < 0:
140140
_api.warn_external('Tight layout not applied. tight_layout '
141-
'cannot make axes width small enough to '
142-
'accommodate all axes decorations')
141+
'cannot make Axes width small enough to '
142+
'accommodate all Axes decorations')
143143
return None
144144
else:
145145
kwargs["wspace"] = hspace / h_axes
@@ -148,8 +148,8 @@ def _auto_adjust_subplotpars(
148148
v_axes = (1 - margin_top - margin_bottom - vspace * (rows - 1)) / rows
149149
if v_axes < 0:
150150
_api.warn_external('Tight layout not applied. tight_layout '
151-
'cannot make axes height small enough to '
152-
'accommodate all axes decorations.')
151+
'cannot make Axes height small enough to '
152+
'accommodate all Axes decorations.')
153153
return None
154154
else:
155155
kwargs["hspace"] = vspace / v_axes
@@ -159,9 +159,9 @@ def _auto_adjust_subplotpars(
159159

160160
def get_subplotspec_list(axes_list, grid_spec=None):
161161
"""
162-
Return a list of subplotspec from the given list of axes.
162+
Return a list of subplotspec from the given list of Axes.
163163
164-
For an instance of axes that does not support subplotspec, None is inserted
164+
For an instance of Axes that does not support subplotspec, None is inserted
165165
in the list.
166166
167167
If grid_spec is given, None is inserted for those not from the given
@@ -201,7 +201,7 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
201201
fig : Figure
202202
axes_list : list of Axes
203203
subplotspec_list : list of `.SubplotSpec`
204-
The subplotspecs of each axes.
204+
The subplotspecs of each Axes.
205205
renderer : renderer
206206
pad : float
207207
Padding between the figure edge and the edges of subplots, as a
@@ -221,7 +221,7 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
221221
None if tight_layout could not be accomplished.
222222
"""
223223

224-
# Multiple axes can share same subplotspec (e.g., if using axes_grid1);
224+
# Multiple Axes can share same subplotspec (e.g., if using axes_grid1);
225225
# we need to group them together.
226226
ss_to_subplots = {ss: [] for ss in subplotspec_list}
227227
for ax, ss in zip(axes_list, subplotspec_list):
@@ -240,7 +240,7 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
240240

241241
span_pairs = []
242242
for ss in ss_to_subplots:
243-
# The intent here is to support axes from different gridspecs where
243+
# The intent here is to support Axes from different gridspecs where
244244
# one's nrows (or ncols) is a multiple of the other (e.g. 2 and 4),
245245
# but this doesn't actually work because the computed wspace, in
246246
# relative-axes-height, corresponds to different physical spacings for

lib/matplotlib/animation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ def _blit_draw(self, artists):
11711171
# of the entire figure.
11721172
updated_ax = {a.axes for a in artists}
11731173
# Enumerate artists to cache Axes backgrounds. We do not draw
1174-
# artists yet to not cache foreground from plots with shared axes
1174+
# artists yet to not cache foreground from plots with shared Axes
11751175
for ax in updated_ax:
11761176
# If we haven't cached the background for the current view of this
11771177
# Axes object, do so now. This might not always be reliable, but

lib/matplotlib/artist.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ def remove(self):
224224
225225
The effect will not be visible until the figure is redrawn, e.g.,
226226
with `.FigureCanvasBase.draw_idle`. Call `~.axes.Axes.relim` to
227-
update the axes limits if desired.
227+
update the Axes limits if desired.
228228
229229
Note: `~.axes.Axes.relim` will not see collections even if the
230-
collection was added to the axes with *autolim* = True.
230+
collection was added to the Axes with *autolim* = True.
231231
232232
Note: there is no support for removing the artist's legend entry.
233233
"""
@@ -299,7 +299,7 @@ def axes(self):
299299
def axes(self, new_axes):
300300
if (new_axes is not None and self._axes is not None
301301
and new_axes != self._axes):
302-
raise ValueError("Can not reset the axes. You are probably "
302+
raise ValueError("Can not reset the Axes. You are probably "
303303
"trying to re-use an artist in more than one "
304304
"Axes which is not supported")
305305
self._axes = new_axes
@@ -340,7 +340,7 @@ def get_window_extent(self, renderer=None):
340340
Be careful when using this function, the results will not update
341341
if the artist window extent of the artist changes. The extent
342342
can change due to any changes in the transform stack, such as
343-
changing the axes limits, the figure size, or the canvas used
343+
changing the Axes limits, the figure size, or the canvas used
344344
(as is done when saving a figure). This can lead to unexpected
345345
behavior where interactive figures will look fine on the screen,
346346
but will save incorrectly.

lib/matplotlib/axes/_axes.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
460460
visibility to True if the automatic choice is not deemed correct.
461461
462462
"""
463-
# to make the axes connectors work, we need to apply the aspect to
464-
# the parent axes.
463+
# to make the Axes connectors work, we need to apply the aspect to
464+
# the parent Axes.
465465
self.apply_aspect()
466466

467467
if transform is None:
@@ -5782,7 +5782,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
57825782
im.set_data(X)
57835783
im.set_alpha(alpha)
57845784
if im.get_clip_path() is None:
5785-
# image does not already have clipping set, clip to axes patch
5785+
# image does not already have clipping set, clip to Axes patch
57865786
im.set_clip_path(self.patch)
57875787
im._scale_norm(norm, vmin, vmax)
57885788
im.set_url(url)
@@ -6519,7 +6519,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
65196519
ret._scale_norm(norm, vmin, vmax)
65206520

65216521
if ret.get_clip_path() is None:
6522-
# image does not already have clipping set, clip to axes patch
6522+
# image does not already have clipping set, clip to Axes patch
65236523
ret.set_clip_path(self.patch)
65246524

65256525
ret.sticky_edges.x[:] = [xl, xr]
@@ -8471,7 +8471,7 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
84718471

84728472
def _get_aspect_ratio(self):
84738473
"""
8474-
Convenience method to calculate the aspect ratio of the axes in
8474+
Convenience method to calculate the aspect ratio of the Axes in
84758475
the display coordinate system.
84768476
"""
84778477
figure_size = self.get_figure().get_size_inches()

0 commit comments

Comments
 (0)