Skip to content

Commit

Permalink
MNT: Change map_projection to projection for Axes creation
Browse files Browse the repository at this point in the history
The GeoAxes class now requires the projection keyword argument rather
than map_projection to be more consistent with how a normal Axes/Subplot
is created.
  • Loading branch information
greglucas committed Jan 5, 2022
1 parent 591fb54 commit 3efcecb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/miscellanea/axes_grid_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def sample_data_3d(shape):
def main():
projection = ccrs.PlateCarree()
axes_class = (GeoAxes,
dict(map_projection=projection))
dict(projection=projection))

lons, lats, times, data = sample_data_3d((6, 73, 145))

Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ def _repr_html_(self):

def _as_mpl_axes(self):
import cartopy.mpl.geoaxes as geoaxes
return geoaxes.GeoAxes, {'map_projection': self}
return geoaxes.GeoAxes, {'projection': self}

def project_geometry(self, geometry, src_crs=None):
"""
Expand Down
26 changes: 15 additions & 11 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,23 +392,27 @@ class GeoAxes(matplotlib.axes.Axes):
"""
name = 'cartopy.geoaxes'

def __init__(self, *args, **kwargs):
def __init__(self, *args, projection=None, **kwargs):
"""
Create a GeoAxes object using standard matplotlib
:class:`~matplotlib.axes.Axes` args and kwargs.
Parameters
----------
map_projection: optional
The target :class:`~cartopy.crs.Projection` of this Axes object.
All other args and keywords are passed through to
:class:`matplotlib.axes.Axes`.
"""
self.projection = kwargs.pop('map_projection')
"""The :class:`cartopy.crs.Projection` of this GeoAxes."""
projection : cartopy.crs.Projection, required
The target projection of this Axes.
"""
if "map_projection" in kwargs:
warnings.warn("The `map_projection` keyword argument is "
"deprecated, use `projection` to instantiate a "
"GeoAxes instead.")
projection = kwargs.pop("map_projection")

# The :class:`cartopy.crs.Projection` of this GeoAxes.
if not isinstance(projection, ccrs.Projection):
raise ValueError("A GeoAxes can only be created with a "
"projection of type cartopy.crs.Projection")
self.projection = projection

super().__init__(*args, **kwargs)
self._gridliners = []
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/tests/mpl/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Test_Axes_add_geometries:
@mock.patch('cartopy.feature.ShapelyFeature')
def test_styler_kwarg(self, ShapelyFeature, add_feature_method):
ax = GeoAxes(plt.figure(), [0, 0, 1, 1],
map_projection=ccrs.Robinson())
projection=ccrs.Robinson())
ax.add_geometries(mock.sentinel.geometries, mock.sentinel.crs,
styler=mock.sentinel.styler, wibble='wobble')

Expand Down

0 comments on commit 3efcecb

Please sign in to comment.