Skip to content

FIX: fix submerged margins algorithm being applied twice #30089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented May 20, 2025

Closes #30076

If a figure had subfigures, the submerged margin algorithm (that tries to deal with margins that are not shared across all axes) would get applied to all axes in the figure, including any that had already been taken care of in a subfigure. This lead to the erroneous behaviour described in #30076.

New version does not apply the algorithm if the axes has already been dealt with in a subfigure.

import matplotlib.pyplot as plt

def test(layout, labelled=False):
    ll = labelled
    fig = plt.figure(figsize=(4, 9), layout=layout)
    fig.suptitle(f'Labelled = {not labelled}', fontsize='small')
    figures = fig.subfigures(4, 1)
    for f in figures.flatten():
        gs = f.add_gridspec(2, 2)
        for i in range(2):
            ax = f.add_subplot(gs[i, 0])
            ax.plot()
            if not labelled:
                ax.set_xlabel('BOOO', fontsize='large')
                labelled = True
        f.add_subplot(gs[:, 1]).plot()
    fig.savefig(f'fig_{not ll}.png')
test("constrained")
#test("constrained", labelled=True)
plt.show()

This PR

now yields:
fig_True

On main

fig_True

Test just makes sure that the appropriate subplots are the same height now. The test fails on main.

@jklymak jklymak added this to the v3.10.4 milestone May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Layout Managers are confused by complex arrangement of sub-figures and gridspec's
2 participants