You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: inset_axes position same as parent axes position. Breaks indicate_axes_zoom #22606
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.frommatplotlibimportcbookimportmatplotlib.pyplotaspltfrommpl_toolkits.axes_grid1.inset_locatorimportinset_axesimportnumpyasnpdefget_demo_image():
z=cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True)
# z is a numpy array of 15x15returnz, (-3, 4, -4, 3)
fig, ax=plt.subplots(figsize=[5, 4])
# make dataZ, extent=get_demo_image()
Z2=np.zeros((150, 150))
ny, nx=Z.shapeZ2[30:30+ny, 30:30+nx] =Zax.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 imagex1, x2, y1, y2=-1.5, -0.9, -2.5, -1.9axins.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()
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.
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.
Activity
rcomer commentedon Mar 5, 2022
I just learned there is also mark_inset which I guess I should have used instead of
indicate_axes_zoom...jklymak commentedon Mar 6, 2022
The main library has inset_axes - is there a reason to use the axes_grid one?
rcomer commentedon Mar 6, 2022
Thanks @jklymak, yes we used the axes_grid function because it works with
Axessubclasses. Our real example needs a Cartopy GeoAxes. It's the same use-case that led me to #22608.rcomer commentedon Apr 7, 2022
Now that #22608 is merged, we will no longer need to use the
axes_gridfunction to get ourGeoAxes.I have the impression that the
axes_gridfunction is somewhat "legacy" and theAxesmethod is being developed in preference. Is that right? If so, I think this issue can be closed.