Thanks to visit codestin.com
Credit goes to github.com

Skip to content

indicate_inset transform support #29174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2024
Merged

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Nov 22, 2024

PR summary

  1. Corrected the indicate_inset docstring, as we are definitely defaulting to transData.
  2. Currently the ends of the connectors that meet the box do not use the passed transform. So against main, my new image test gives
    main
  3. Set the axes property on the rectangle so that Cartopy transforms will work, and we can do things like
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature

main_map_proj = ccrs.TransverseMercator()
pcarree = ccrs.PlateCarree()

fig, ax = plt.subplots(subplot_kw={"projection": main_map_proj})

ax.set_extent([-50, 15, 50, 70], crs=pcarree)
ax.add_feature(cfeature.OCEAN.with_scale('50m'), facecolor="lightsteelblue", zorder=1,
               edgecolor="k", lw=0.2)

inset_ax = ax.inset_axes((0.05, 0.05, 0.3, 0.3), projection=pcarree)

inset_extent = [-44, -38, 63, 66]
inset_ax.set_extent(inset_extent, crs=pcarree)
inset_ax.add_feature(cfeature.OCEAN, facecolor="lightsteelblue", zorder=1)

ax.indicate_inset_zoom(inset_ax, edgecolor="black", transform=pcarree)

x = [inset_extent[0], inset_extent[1], inset_extent[1], inset_extent[0]]
y = [inset_extent[2], inset_extent[2], inset_extent[3], inset_extent[3]]
for a in ax, inset_ax:
    a.scatter(x, y, c=range(4), s=150, transform=pcarree)

plt.show()

image

PR checklist

@rcomer rcomer marked this pull request as draft November 22, 2024 20:12
@rcomer rcomer force-pushed the inset-conn-transform branch 2 times, most recently from c8e7643 to ba851c1 Compare November 22, 2024 20:43


@image_comparison(['zoom_inset_transform.png'], remove_text=True, style='mpl20',
tol=0.01)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MacOS tests need the 0.01 tolerance.

@rcomer rcomer marked this pull request as ready for review November 22, 2024 21:14
@rcomer rcomer force-pushed the inset-conn-transform branch 2 times, most recently from 470b488 to 0d57221 Compare November 22, 2024 21:52
@rcomer rcomer force-pushed the inset-conn-transform branch from 0d57221 to 95ed490 Compare November 23, 2024 08:40
# Set axes on the rectangle (required for some external transforms to work) as
# well as the InsetIndicator artist.
self.rectangle.axes = new_axes
artist.Artist.axes.fset(self, new_axes)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the setter logic here from the artist within artist example. I would not have figured it out by myself - thanks @QuLogic for putting it in the example!

@QuLogic QuLogic merged commit a3682f3 into matplotlib:main Dec 20, 2024
42 of 43 checks passed
@QuLogic QuLogic added this to the v3.11.0 milestone Dec 20, 2024
@rcomer rcomer deleted the inset-conn-transform branch December 20, 2024 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants