Skip to content

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

Closed
@boffi

Description

@boffi

Bug summary

When I run the code below

  1. compressed.png and constrained.png are (visually) identical, and the axes in the left of each sub-figure are getting smaller and smaller
  2. tight.png has all the axes in each sub-figure the same sizes, but those sizes are wrong
  3. none.png is correct (all the sizes remain unchanged, the sizes are OK) but the axes decorations overlap the plotting area

For your convenience I've uploaded the image files produced by my code.

Thank you in advance — gb


This behaviour was brought to my attention by
https://stackoverflow.com/questions/79614691/why-are-the-subplots-in-the-subfigures-getting-smaller

Code for reproduction

import matplotlib.pyplot as plt


def test(layout):
    fig = plt.figure(figsize=(12, 16), layout=layout)
    figures = fig.subfigures(4, 2)

    for f in figures.flatten():
        gs = f.add_gridspec(3, 2)
        for i in range(3):
            f.add_subplot(gs[i, 0]).plot()
        f.add_subplot(gs[:, 1]).plot()
    fig.savefig(layout + ".png")


test("compressed")
test("constrained")
test("none")
test("tight")

Actual outcome

Image
Image
Image
Image

Expected outcome

Something like none.png w/o the axes decoration overlapping the plot areas

Additional information

No response

Operating system

Open Suse Tumbleweed

Matplotlib Version

3.10.1

Matplotlib Backend

qtagg

Python version

Python 3.13.3

Jupyter version

No response

Installation

Linux package manager

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions