Skip to content

[Bug]: inset_axes position same as parent axes position. Breaks indicate_axes_zoom #22606

Closed as not planned
@rcomer

Description

@rcomer

Bug summary

An inset axes created using mpl_toolkits.axes_grid1.inset_locator.inset_axes seems to inherit its position from the parent axes. This prevents any connection lines being drawn by indicate_inset_zoom showing up, as their "visible" attributes depend on the result of get_position.

Code for reproduction

# Adapted from the gallery example, but replacing the axes method with the function from toolkits.

from matplotlib import cbook
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import numpy as np


def get_demo_image():
    z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True)
    # z is a numpy array of 15x15
    return z, (-3, 4, -4, 3)

fig, ax = plt.subplots(figsize=[5, 4])

# make data
Z, extent = get_demo_image()
Z2 = np.zeros((150, 150))
ny, nx = Z.shape
Z2[30:30+ny, 30:30+nx] = Z

ax.imshow(Z2, extent=extent, origin="lower")

# inset axes....
axins = inset_axes(ax, width="50%", height="50%")
axins.imshow(Z2, extent=extent, origin="lower")

# sub region of the original image
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
axins.set_xticklabels([])
axins.set_yticklabels([])

print("main axes position:", ax.get_position())
print("inset axes position:", axins.get_position())

ax.indicate_inset_zoom(axins, edgecolor="black")

plt.show()

Actual outcome

main axes position: Bbox(x0=0.20449999999999996, y0=0.10999999999999999, x1=0.8205, y1=0.88)
inset axes position: Bbox(x0=0.20449999999999996, y0=0.10999999999999999, x1=0.8205, y1=0.88)

zoom_no_indicate

Expected outcome

Plot should have connecting lines, similar to the zoom region inset axes gallery example.

Additional information

No response

Operating system

RHEL

Matplotlib Version

3.5.1

Matplotlib Backend

TKAgg

Python version

3.10.2

Jupyter version

No response

Installation

conda

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