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

Appearance settings

Commit 5974a56

Browse filesBrowse files
committed
FIX: constrained layout uneven gridspec issues
1 parent aed4b74 commit 5974a56
Copy full SHA for 5974a56

File tree

Expand file treeCollapse file tree

1 file changed

+30
-16
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+30
-16
lines changed

‎lib/matplotlib/_constrained_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_constrained_layout.py
+30-16Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,19 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
361361
'bottom')
362362

363363
###########
364-
# Now we make the widths and heights similar.
364+
# Now we make the widths and heights of position boxes
365+
# similar. (i.e the spine locations)
365366
# This allows vertically stacked subplots to have
366-
# different sizes if they occupy different ammounts
367+
# different sizes if they occupy different amounts
367368
# of the gridspec: i.e.
368369
# gs = gridspec.GridSpec(3,1)
369370
# ax1 = gs[0,:]
370371
# ax2 = gs[1:,:]
371372
# then drows0 = 1, and drowsC = 2, and ax2
372373
# should be at least twice as large as ax1.
374+
# But it can be more than twice as large because
375+
# it needs less room for the labeling.
376+
#
373377
# For height, this only needs to be done if the
374378
# subplots share a column. For width if they
375379
# share a row.
@@ -387,31 +391,41 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
387391
dcolsC = (colnumCmax - colnumCmin + 1)
388392
dcols0 = (colnum0max - colnum0min + 1)
389393

390-
if drowsC > drows0:
394+
if height0 > heightC:
391395
if in_same_column(ss0, ssc):
392396
ax._poslayoutbox.constrain_height_min(
393-
axc._poslayoutbox.height * drows0 * height0
394-
/ drowsC / heightC)
395-
elif drowsC < drows0:
396-
if in_same_column(ss0, ssc):
397+
axc._poslayoutbox.height * height0 /
398+
heightC)
397399
axc._poslayoutbox.constrain_height_min(
398-
ax._poslayoutbox.height * drowsC * heightC
399-
/ drows0 / drowsC)
400+
ax._poslayoutbox.height * heightC /
401+
(height0*1.8))
400402
else:
403+
if in_same_column(ss0, ssc):
404+
axc._poslayoutbox.constrain_height_min(
405+
ax._poslayoutbox.height * heightC /
406+
(height0))
407+
ax._poslayoutbox.constrain_height_min(
408+
ax._poslayoutbox.height * height0 /
409+
(heightC*1.8))
410+
if drows0 == drowsC:
401411
ax._poslayoutbox.constrain_height(
402412
axc._poslayoutbox.height * height0 / heightC)
403413
# widths...
404-
if dcolsC > dcols0:
414+
if width0 > widthC:
405415
if in_same_row(ss0, ssc):
406416
ax._poslayoutbox.constrain_width_min(
407-
axc._poslayoutbox.width * dcols0 * width0
408-
/ dcolsC / widthC)
409-
elif dcolsC < dcols0:
410-
if in_same_row(ss0, ssc):
417+
axc._poslayoutbox.width * width0 / widthC)
411418
axc._poslayoutbox.constrain_width_min(
412-
ax._poslayoutbox.width * dcolsC * widthC
413-
/ dcols0 / width0)
419+
ax._poslayoutbox.width * widthC /
420+
(width0*1.8))
414421
else:
422+
if in_same_row(ss0, ssc):
423+
axc._poslayoutbox.constrain_width_min(
424+
ax._poslayoutbox.width * widthC / width0)
425+
ax._poslayoutbox.constrain_width_min(
426+
axc._poslayoutbox.width * width0 /
427+
(widthC*1.8))
428+
if dcols0 == dcolsC:
415429
ax._poslayoutbox.constrain_width(
416430
axc._poslayoutbox.width * width0 / widthC)
417431

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.