Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb036e26

Browse files
committed
DOC: improve documentation in new functions
1 parent803b400 commitb036e26

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

‎lib/matplotlib/_constrained_layout.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
9393
"""
9494

9595
# make layoutgrid tree...
96-
_layoutgrids=None
97-
_layoutgrids=_make_layoutgrids(fig,_layoutgrids)
96+
_layoutgrids=_make_layoutgrids(fig,None)
9897
ifnot_layoutgrids['hasgrids']:
9998
_api.warn_external('There are no gridspecs with layoutgrids. '
10099
'Possibly did not call parent GridSpec with the'
@@ -134,6 +133,14 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
134133

135134

136135
def_make_layoutgrids(fig,_layoutgrids):
136+
"""
137+
Make the layoutgrid tree.
138+
139+
(Sub)Figures get a layoutgrid so we can have figure margins.
140+
141+
Gridspecs that are attached to axes get a layoutgrid so axes
142+
can have margins.
143+
"""
137144

138145
if_layoutgridsisNone:
139146
_layoutgrids=dict()
@@ -144,7 +151,10 @@ def _make_layoutgrids(fig, _layoutgrids):
144151
else:
145152
# subfigure
146153
gs=fig._subplotspec.get_gridspec()
154+
# its possible the gridspec containing this subfigure hasn't
155+
# been added to the tree yet:
147156
_layoutgrids=_make_layoutgrids_gs(_layoutgrids,gs)
157+
# add the layoutgrid for the subfigure:
148158
parentlb=_layoutgrids[gs]
149159
_layoutgrids[fig]=layoutgrid.LayoutGrid(
150160
parent=parentlb,
@@ -154,9 +164,11 @@ def _make_layoutgrids(fig, _layoutgrids):
154164
nrows=1,ncols=1,
155165
parent_pos=(fig._subplotspec.rowspan,
156166
fig._subplotspec.colspan))
167+
# recursively do all subfigures in this figure...
157168
forsfiginfig.subfigs:
158169
_layoutgrids=_make_layoutgrids(sfig,_layoutgrids)
159170

171+
# for each axes at the local level add its gridspec:
160172
foraxinfig._localaxes.as_list():
161173
ifhasattr(ax,'get_subplotspec'):
162174
gs=ax.get_subplotspec().get_gridspec()
@@ -166,9 +178,14 @@ def _make_layoutgrids(fig, _layoutgrids):
166178

167179

168180
def_make_layoutgrids_gs(_layoutgrids,gs):
181+
"""
182+
Make the layoutgrid for a gridspec (and anything nested in the gridspec)
183+
"""
169184

170185
ifgsin_layoutgridsorgs.figureisNone:
171186
return_layoutgrids
187+
# in order to do constrained_layout there has to be at least *one*
188+
# gridspec in the tree:
172189
_layoutgrids['hasgrids']=True
173190
ifnothasattr(gs,'_subplot_spec'):
174191
# normal gridspec
@@ -182,17 +199,20 @@ def _make_layoutgrids_gs(_layoutgrids, gs):
182199
width_ratios=gs.get_width_ratios(),
183200
height_ratios=gs.get_height_ratios())
184201
else:
185-
# this is agridspec inside a subplotspec...
202+
# this is agridspecfromsubplotspec:
186203
subplot_spec=gs._subplot_spec
187204
parentgs=subplot_spec.get_gridspec()
205+
# if its a nested gridspec its possible the parent is not in there yet:
188206
ifparentgsnotin_layoutgrids:
189207
_layoutgrids=_make_layoutgrids_gs(_layoutgrids,parentgs)
190208
subspeclb=_layoutgrids[parentgs]
191-
_layoutgrids[str(gs)+'top']=layoutgrid.LayoutGrid(
192-
parent=subspeclb,
193-
name=subspeclb.name+'.top'+layoutgrid.seq_id(),
194-
nrows=1,ncols=1,
195-
parent_pos=(subplot_spec.rowspan,subplot_spec.colspan))
209+
# gridspecfromsubplotspec need an outer container:
210+
ifstr(gs)+'top'notin_layoutgrids:
211+
_layoutgrids[str(gs)+'top']=layoutgrid.LayoutGrid(
212+
parent=subspeclb,
213+
name=subspeclb.name+'.top'+layoutgrid.seq_id(),
214+
nrows=1,ncols=1,
215+
parent_pos=(subplot_spec.rowspan,subplot_spec.colspan))
196216
_layoutgrids[gs]=layoutgrid.LayoutGrid(
197217
parent=_layoutgrids[str(gs)+'top'],
198218
name=(_layoutgrids[str(gs)+'top'].name+'.gridspec'+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp