Skip to content
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

annotate #1720

Closed
shaharkadmiel opened this issue Jan 27, 2021 · 2 comments · Fixed by #2065
Closed

annotate #1720

shaharkadmiel opened this issue Jan 27, 2021 · 2 comments · Fixed by #2065
Milestone

Comments

@shaharkadmiel
Copy link

It is a bit cumbersome and unintuitive to use the annotate method with GeoAxes (see this discussion on stackoverflow).

To make the ax.annotate method more like the other GeoAxes methods (like plot, scatter, etc.), I suggest this thin wrapper:

class GeoAxes():
    ...

    def annotate(self, *args, **kwargs):
        crs = kwargs.pop('transform', self.projection)
        transform = crs._as_mpl_transform(self)
        kwargs['xycoords'] = transform
        xy = kwargs['xy']
        return self.annotate(*args, **kwargs)

This way the transform keyword is used to properly construct the xycoords transform.

Example:

ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()

ny_lon, ny_lat = -75, 43
delhi_lon, delhi_lat = 77.23, 28.61

ax.plot(
    [ny_lon, delhi_lon], [ny_lat, delhi_lat], '-bo', transform=ccrs.Geodetic(),
)

ax.annotate('New York', xy=(ny_lon, ny_lat), xytext=(-30, +15),
         textcoords='offset points', ha='center', va='center',
         arrowprops=dict(arrowstyle='->'), 
         transform=ccrs.Geodetic())

ax.annotate('Delhi', xy=(delhi_lon, delhi_lat), xytext=(+30, -15),
         textcoords='offset points', ha='center', va='center',
         arrowprops=dict(arrowstyle='->'), 
         transform=ccrs.Geodetic())

image

@QuLogic
Copy link
Member

QuLogic commented Mar 7, 2021

Seems pretty reasonable, though you have to be careful to only do so if the coords are really for data space; would you like to open a PR?

@shaharkadmiel
Copy link
Author

Thanks @QuLogic , I can make a pull request.
Indeed, I will have to first check that xycoords is either 'data' or unset (the default is 'data') and only then assign the transform to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants