Skip to content

[Bug]: Axes placement and tight_layout() #24226

@suuuehgi

Description

@suuuehgi

Bug summary

Figure.tight_layout() changes relative placement of axes.

I don't know where this is a bug, a feature request or just unavoidable behavior.

(In this simple case, moving .tight_layout() ahead of .add_axes fixes it.)

Code for reproduction

from matplotlib import pyplot as plt
import matplotlib

fig, axs = plt.subplots( nrows=2, sharex=True )

# left, bottom, width, height
box = matplotlib.transforms.Bbox.from_bounds(.5, 0, .1, .1)

fig.add_axes(fig.transFigure.inverted().transform_bbox( axs[0].transAxes.transform_bbox(box)))
fig.add_axes(fig.transFigure.inverted().transform_bbox( axs[1].transAxes.transform_bbox(box)))

fig.tight_layout()

Actual outcome

github

Expected outcome

github2

Additional information

Related issue: #24225

Operating system

Arch

Matplotlib Version

3.6.1

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.10.7

Jupyter version

Jupyter Lab v. 3.4.5

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions