Skip to content

[Bug]: pyplot.Figure.add_axes does not respect the transform argument #24225

@suuuehgi

Description

@suuuehgi

Bug summary

pyplot.Figure.add_axes does not seem to respect the transform argument.

Edit: This might already exist for a while: #8986

Code for reproduction

from matplotlib import pyplot as plt

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

# left, bottom, width, height
fig.add_axes([.5, .5, .1, .1], transform=axs[1].transAxes)

fig.tight_layout()

Actual outcome

github

Expected outcome

github2

I found this workaround in the above-mentioned issue.

import matplotlib
box = matplotlib.transforms.Bbox.from_bounds(.5, .5, .1, .1)
fig.add_axes(fig.transFigure.inverted().transform_bbox( axs[1].transAxes.transform_bbox(box)))

Additional information

No response

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions