Skip to content

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

Closed as not planned

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

Activity

  1. rcomer commented on Mar 5, 2022

    @rcomer
    MemberAuthor

    I just learned there is also mark_inset which I guess I should have used instead of indicate_axes_zoom...

  2. jklymak commented on Mar 6, 2022

    @jklymak
    Member

    The main library has inset_axes - is there a reason to use the axes_grid one?

  3. rcomer commented on Mar 6, 2022

    @rcomer
    MemberAuthor

    Thanks @jklymak, yes we used the axes_grid function because it works with Axes subclasses. Our real example needs a Cartopy GeoAxes. It's the same use-case that led me to #22608.

  4. rcomer commented on Apr 7, 2022

    @rcomer
    MemberAuthor

    Now that #22608 is merged, we will no longer need to use the axes_grid function to get our GeoAxes.

    I have the impression that the axes_grid function is somewhat "legacy" and the Axes method is being developed in preference. Is that right? If so, I think this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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