1
1
"""
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,
4
4
ticklabels) and some dependent artists are also dealt with (colorbar,
5
5
suptitle).
6
6
7
7
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.
9
9
using `~matplotlib.gridspec.GridSpecFromSubplotSpec`). Axes placed using
10
10
``figure.subplots()`` or ``figure.add_subplots()`` will participate in the
11
11
layout. Axes manually placed via ``figure.add_axes()`` will not.
33
33
is the width or height of each column/row minus the size of the margins.
34
34
35
35
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
38
38
left ticklabels, and the ylabel if it exists. The right margin may include a
39
39
colorbar, the bottom margin the xaxis decorations, and the top margin the
40
40
title.
@@ -73,11 +73,11 @@ def do_constrained_layout(fig, h_pad, w_pad,
73
73
`.Figure` instance to do the layout in.
74
74
75
75
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.
77
77
78
78
hspace, wspace : float
79
79
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 .
81
81
A value of 0.2 for a three-column layout would have a space
82
82
of 0.1 of the figure width between each column.
83
83
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,
111
111
# larger/smaller). This second reposition tends to be much milder,
112
112
# so doing twice makes things work OK.
113
113
114
- # make margins for all the axes and subfigures in the
114
+ # make margins for all the Axes and subfigures in the
115
115
# figure. Add margins for colorbars...
116
116
make_layout_margins (layoutgrids , fig , renderer , h_pad = h_pad ,
117
117
w_pad = w_pad , hspace = hspace , wspace = wspace )
@@ -128,7 +128,7 @@ def do_constrained_layout(fig, h_pad, w_pad,
128
128
129
129
warn_collapsed = ('constrained_layout not applied because '
130
130
'axes sizes collapsed to zero. Try making '
131
- 'figure larger or axes decorations smaller.' )
131
+ 'figure larger or Axes decorations smaller.' )
132
132
if check_no_collapsed_axes (layoutgrids , fig ):
133
133
reposition_axes (layoutgrids , fig , renderer , h_pad = h_pad ,
134
134
w_pad = w_pad , hspace = hspace , wspace = wspace )
@@ -152,7 +152,7 @@ def make_layoutgrids(fig, layoutgrids, rect=(0, 0, 1, 1)):
152
152
153
153
(Sub)Figures get a layoutgrid so we can have figure margins.
154
154
155
- Gridspecs that are attached to axes get a layoutgrid so axes
155
+ Gridspecs that are attached to Axes get a layoutgrid so Axes
156
156
can have margins.
157
157
"""
158
158
@@ -182,7 +182,7 @@ def make_layoutgrids(fig, layoutgrids, rect=(0, 0, 1, 1)):
182
182
for sfig in fig .subfigs :
183
183
layoutgrids = make_layoutgrids (sfig , layoutgrids )
184
184
185
- # for each axes at the local level add its gridspec:
185
+ # for each Axes at the local level add its gridspec:
186
186
for ax in fig ._localaxes :
187
187
gs = ax .get_gridspec ()
188
188
if gs is not None :
@@ -239,7 +239,7 @@ def make_layoutgrids_gs(layoutgrids, gs):
239
239
240
240
def check_no_collapsed_axes (layoutgrids , fig ):
241
241
"""
242
- Check that no axes have collapsed to zero size.
242
+ Check that no Axes have collapsed to zero size.
243
243
"""
244
244
for sfig in fig .subfigs :
245
245
ok = check_no_collapsed_axes (layoutgrids , sfig )
@@ -270,7 +270,7 @@ def compress_fixed_aspect(layoutgrids, fig):
270
270
extraw = np .zeros (gs .ncols )
271
271
extrah = np .zeros (gs .nrows )
272
272
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'
274
274
'all from the same gridspec' )
275
275
orig = ax .get_position (original = True )
276
276
actual = ax .get_position (original = False )
@@ -282,7 +282,7 @@ def compress_fixed_aspect(layoutgrids, fig):
282
282
extrah [sub .rowspan ] = np .maximum (extrah [sub .rowspan ], dh )
283
283
284
284
if gs is None :
285
- raise ValueError ('Cannot do compressed layout if no axes '
285
+ raise ValueError ('Cannot do compressed layout if no Axes '
286
286
'are part of a gridspec.' )
287
287
w = np .sum (extraw ) / 2
288
288
layoutgrids [fig ].edit_margin_min ('left' , w )
@@ -313,7 +313,7 @@ def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,
313
313
nrows , ncols = gs .get_geometry ()
314
314
# there are two margins for each direction. The "cb"
315
315
# margins are for pads and colorbars, the non-"cb" are
316
- # for the axes decorations (labels etc).
316
+ # for the Axes decorations (labels etc).
317
317
margin = {'leftcb' : w_pad , 'rightcb' : w_pad ,
318
318
'bottomcb' : h_pad , 'topcb' : h_pad ,
319
319
'left' : 0 , 'right' : 0 ,
@@ -335,7 +335,7 @@ def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,
335
335
def make_layout_margins (layoutgrids , fig , renderer , * , w_pad = 0 , h_pad = 0 ,
336
336
hspace = 0 , wspace = 0 ):
337
337
"""
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
339
339
*axes* layoutbox be a minimum size that can accommodate the
340
340
decorations on the axis.
341
341
@@ -379,7 +379,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
379
379
margin = get_margin_from_padding (ax , w_pad = w_pad , h_pad = h_pad ,
380
380
hspace = hspace , wspace = wspace )
381
381
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
383
383
# and its position (plus the padding from above)
384
384
margin ['left' ] += pos .x0 - bbox .x0
385
385
margin ['right' ] += bbox .x1 - pos .x1
@@ -388,7 +388,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
388
388
margin ['top' ] += bbox .y1 - pos .y1
389
389
390
390
# 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.
392
392
for cbax in ax ._colorbars :
393
393
# note pad is a fraction of the parent width...
394
394
pad = colorbar_get_pad (layoutgrids , cbax )
@@ -493,14 +493,14 @@ def match_submerged_margins(layoutgrids, fig):
493
493
"""
494
494
Make the margins that are submerged inside an Axes the same size.
495
495
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
497
497
from one another to have the same size.
498
498
499
499
This gives the proper layout for something like::
500
500
fig = plt.figure(constrained_layout=True)
501
501
axs = fig.subplot_mosaic("AAAB\n CCDD")
502
502
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
504
504
margin width between the two columns in C has no width by default,
505
505
whereas the margins between the two columns of D are set by the
506
506
width of the margin between A and B. However, obviously the user would
@@ -613,7 +613,7 @@ def get_cb_parent_spans(cbax):
613
613
614
614
def get_pos_and_bbox (ax , renderer ):
615
615
"""
616
- Get the position and the bbox for the axes .
616
+ Get the position and the bbox for the Axes .
617
617
618
618
Parameters
619
619
----------
@@ -642,7 +642,7 @@ def get_pos_and_bbox(ax, renderer):
642
642
def reposition_axes (layoutgrids , fig , renderer , * ,
643
643
w_pad = 0 , h_pad = 0 , hspace = 0 , wspace = 0 ):
644
644
"""
645
- Reposition all the axes based on the new inner bounding box.
645
+ Reposition all the Axes based on the new inner bounding box.
646
646
"""
647
647
trans_fig_to_subfig = fig .transFigure - fig .transSubfigure
648
648
for sfig in fig .subfigs :
0 commit comments