8000 TST and fix submerged · matplotlib/matplotlib@ed8b772 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed8b772

Browse files
committed
TST and fix submerged
1 parent 3d72132 commit ed8b772

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,21 +321,27 @@ def _match_submerged_margins(fig):
321321
nc = len(ss1.colspan)
322322
if nc > 1:
323323
maxsubl = np.max(
324-
lg1.margin_vals['left'][ss1.colspan[1:]])
324+
lg1.margin_vals['left'][ss1.colspan[1:]] +
325+
lg1.margin_vals['leftcb'][ss1.colspan[1:]]
326+
)
325327
maxsubr = np.max(
326-
lg1.margin_vals['right'][ss1.colspan[:-1]])
328+
lg1.margin_vals['right'][ss1.colspan[:-1]] +
329+
lg1.margin_vals['rightcb'][ss1.colspan[:-1]]
330+
)
327331
for ax2 in axs:
328332
ss2 = ax2.get_subplotspec()
329333
lg2 = ss2.get_gridspec()._layoutgrid
330334
if lg2 is not None:
331335
nc = len(ss2.colspan)
332336
if nc > 1:
333337
maxsubl2 = np.max(
334-
lg2.margin_vals['left'][ss2.colspan[1:]])
338+
lg2.margin_vals['left'][ss2.colspan[1:]] +
339+
lg2.margin_vals['leftcb'][ss2.colspan[1:]])
335340
if maxsubl2 > maxsubl:
336341
maxsubl = maxsubl2
337342
maxsubr2 = np.max(
338-
lg2.margin_vals['right'][ss2.colspan[:-1]])
343+
lg2.margin_vals['right'][ss2.colspan[:-1]] +
344+
lg2.margin_vals['rightcb'][ss2.colspan[:-1]])
339345
if maxsubr2 > maxsubr:
340346
maxsubr = maxsubr2
341347
for i in ss1.colspan[1:]:
@@ -347,9 +353,13 @@ def _match_submerged_margins(fig):
347353
nc = len(ss1.rowspan)
348354
if nc > 1:
349355
maxsubt = np.max(
350-
lg1.margin_vals['top'][ss1.rowspan[1:]])
356+
lg1.margin_vals['top'][ss1.rowspan[1:]] +
357+
lg1.margin_vals['topcb'][ss1.rowspan[1:]]
358+
)
351359
maxsubb = np.max(
352-
lg1.margin_vals['bottom'][ss1.rowspan[:-1]])
360+
lg1.margin_vals['bottom'][ss1.rowspan[:-1]] +
361+
lg1.margin_vals['bottomcb'][ss1.rowspan[:-1]]
362+
)
353363

354364
for ax2 in axs:
355365
ss2 = ax2.get_subplotspec()
@@ -358,11 +368,15 @@ def _match_submerged_margins(fig):
358368
nc = len(ss2.rowspan)
359369
if nc > 1:
360370
maxsubt2 = np.max(
361-
lg2.margin_vals['top'][ss2.rowspan[1:]])
371+
lg2.margin_vals['top'][ss2.rowspan[1:]] +
372+
lg2.margin_vals['topcb'][ss2.rowspan[1:]]
373+
)
362374
if maxsubt2 > maxsubt:
363375
maxsubt = maxsubt2
364376
maxsubb2 = np.max(
365-
lg2.margin_vals['bottom'][ss2.rowspan[:-1]])
377+
lg2.margin_vals['bottom'][ss2.rowspan[:-1]] +
378+
lg2.margin_vals['bottomcb'][ss2.rowspan[:-1]]
379+
)
366380
if maxsubb2 > maxsubb:
367381
maxsubb = maxsubb2
368382
for i in ss1.rowspan[1:]:
Loading
Loading
Loading

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def test_constrained_layout11rat():
215215
@image_comparison(['constrained_layout12.png'])
216216
def test_constrained_layout12():
217217
"""Test that very unbalanced labeling still works."""
218-
fig = plt.figure(constrained_layout=True, figsize=(6, 6))
218+
fig = plt.figure(constrained_layout=True, figsize=(6, 8))
219219

220220
gs0 = gridspec.GridSpec(6, 2, figure=fig)
221221

@@ -395,3 +395,36 @@ def test_hidden_axes():
395395

396396
np.testing.assert_allclose(
397397
extents1, [0.045552, 0.543288, 0.47819, 0.982638], rtol=1e-5)
398+
399+
400+
def test_colorbar_align():
401+
for location in ['right', 'left', 'top', 'bottom']:
402+
fig, axs = plt.subplots(2, 2, constrained_layout=True)
403+
cbs = []
404+
for nn, ax in enumerate(axs.flat):
405+
ax.tick_params(direction='in')
406+
pc = example_pcolor(ax)
407+
cb = fig.colorbar(pc, ax=ax, location=location, shrink=0.6,
408+
pad=0.04)
409+
cbs += [cb]
410+
cb.ax.tick_params(direction='in')
411+
if nn != 1:
412+
cb.ax.xaxis.set_ticks([])
413+
cb.ax.yaxis.set_ticks([])
414+
if nn != 1:
415+
ax.set_xticklabels('')
416+
ax.set_yticklabels('')
417+
fig.set_constrained_layout_pads(w_pad=4 / 72, h_pad=4 / 72, hspace=0.1,
418+
wspace=0.1)
419+
420+
fig.canvas.draw()
421+
if location in ['left', 'right']:
422+
np.testing.assert_allclose(cbs[0].ax.get_position().x0,
423+
cbs[2].ax.get_position().x0)
424+
np.testing.assert_allclose(cbs[1].ax.get_position().x0,
425+
cbs[3].ax.get_position().x0)
426+
else:
427+
np.testing.assert_allclose(cbs[0].ax.get_position().y0,
428+
cbs[1].ax.get_position().y0)
429+
np.testing.assert_allclose(cbs[2].ax.get_position().y0,
430+
cbs[3].ax.get_position().y0)

0 commit comments

Comments
 (0)
0