Skip to content

Commit f822dba

Browse files
authored
Merge pull request #11811 from jklymak/backport-cl-overflow
Backport: Pull Request #11330: FIX: Don't let constrained_layout counter overflow
2 parents 6bf26c6 + 409c023 commit f822dba

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

lib/matplotlib/_constrained_layout.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
272272
# This routine makes all the subplot spec containers
273273
# have the correct arrangement. It just stacks the
274274
# subplot layoutboxes in the correct order...
275-
arange_subplotspecs(child, hspace=hspace, wspace=wspace)
275+
_arange_subplotspecs(child, hspace=hspace, wspace=wspace)
276276

277277
# - Align right/left and bottom/top spines of appropriate subplots.
278278
# - Compare size of subplotspec including height and width ratios
@@ -443,7 +443,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
443443
ax._set_position(newpos, which='original')
444444

445445

446-
def arange_subplotspecs(gs, hspace=0, wspace=0):
446+
def _arange_subplotspecs(gs, hspace=0, wspace=0):
447447
"""
448448
arange the subplotspec children of this gridspec, and then recursively
449449
do the same of any gridspec children of those gridspecs...
@@ -453,9 +453,8 @@ def arange_subplotspecs(gs, hspace=0, wspace=0):
453453
if child._is_subplotspec_layoutbox():
454454
for child2 in child.children:
455455
# check for gridspec children...
456-
name = (child2.name).split('.')[-1][:-3]
457-
if name == 'gridspec':
458-
arange_subplotspecs(child2, hspace=hspace, wspace=wspace)
456+
if child2._is_gridspec_layoutbox():
457+
_arange_subplotspecs(child2, hspace=hspace, wspace=wspace)
459458
sschildren += [child]
460459
# now arrange the subplots...
461460
for child0 in sschildren:

lib/matplotlib/_layoutbox.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,16 @@ def _is_subplotspec_layoutbox(self):
358358
Helper to check if this layoutbox is the layoutbox of a
359359
subplotspec
360360
'''
361-
name = (self.name).split('.')[-1][:-3]
362-
if name == 'ss':
363-
return True
364-
return False
361+
name = (self.name).split('.')[-1]
362+
return name[:2] == 'ss'
365363

366364
def _is_gridspec_layoutbox(self):
367365
'''
368366
Helper to check if this layoutbox is the layoutbox of a
369367
gridspec
370368
'''
371-
name = (self.name).split('.')[-1][:-3]
372-
if name == 'gridspec':
373-
return True
374-
return False
369+
name = (self.name).split('.')[-1]
370+
return name[:8] == 'gridspec'
375371

376372
def find_child_subplots(self):
377373
'''
@@ -650,7 +646,7 @@ def seq_id():
650646

651647
global _layoutboxobjnum
652648

653-
return ('%03d' % (next(_layoutboxobjnum)))
649+
return ('%06d' % (next(_layoutboxobjnum)))
654650

655651

656652
def print_children(lb):

lib/matplotlib/tests/test_axes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3996,7 +3996,7 @@ def test_psd_noise():
39963996

39973997

39983998
@image_comparison(baseline_images=['csd_freqs'], remove_text=True,
3999-
extensions=['png'])
3999+
extensions=['png'], tol=0.002)
40004000
def test_csd_freqs():
40014001
'''test axes.csd with sinusoidal stimuli'''
40024002
n = 10000

0 commit comments

Comments
 (0)