Skip to content

[Bug]: inset_locator is broken when used with subfigures #24589

Closed
@amcpherson

Description

@amcpherson

Bug summary

When using inset_locator functions in subfigures, the plots are not placed correctly. Adapting this demo
https://matplotlib.org/stable/gallery/axes_grid1/demo_colorbar_of_inset_axes.html
to use subfigures shows incorrect plots.

Code for reproduction

from matplotlib import cbook
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes


fig = plt.figure()
fig1, fig2 = fig.subfigures(nrows=2, ncols=1, height_ratios=[1, 1], squeeze=True)

ax = fig1.subplots()
ax.set(aspect=1, xlim=(-15, 15), ylim=(-20, 5))

Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True)
extent = (-3, 4, -4, 3)

axins = zoomed_inset_axes(ax, zoom=2, loc='upper left')
axins.set(xticks=[], yticks=[])
im = axins.imshow(Z, extent=extent, origin="lower")

# colorbar
cax = inset_axes(axins,
                 width="5%",  # width = 10% of parent_bbox width
                 height="100%",  # height : 50%
                 loc='lower left',
                 bbox_to_anchor=(1.05, 0., 1, 1),
                 bbox_transform=axins.transAxes,
                 borderpad=0,
                 )
fig.colorbar(im, cax=cax)

plt.show()

Actual outcome

image

Expected outcome

Something more similar to https://matplotlib.org/stable/gallery/axes_grid1/demo_colorbar_of_inset_axes.html

Additional information

No response

Operating system

OS/X

Matplotlib Version

3.6.1

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

No response

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!status: has patchpatch suggested, PR still neededtopic: mpl_toolkit

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions