-
Notifications
You must be signed in to change notification settings - Fork 388
Closed
Milestone
Description
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())
Metadata
Metadata
Assignees
Labels
No labels