def __init__(self, *args, **kwargs): if "map_projection" in kwargs: map_projection=kwargs.pop("map_projection") else: map_projection = cartopy.crs.NorthPolarStereo() print("map_projection keyword not set, setting it to cartopy.crs.NorthPolarStereo()") GeoAxes.__init__(self, map_projection=map_projection,*args, **kwargs)
def test_styler_kwarg(self, ShapelyFeature, add_feature_method): ax = GeoAxes(plt.figure(), [0, 0, 1, 1], map_projection=ccrs.Robinson()) ax.add_geometries(mock.sentinel.geometries, mock.sentinel.crs, styler=mock.sentinel.styler, wibble='wobble') ShapelyFeature.assert_called_once_with( mock.sentinel.geometries, mock.sentinel.crs, wibble='wobble') add_feature_method.assert_called_once_with( ShapelyFeature(), styler=mock.sentinel.styler)
def test_styler_kwarg(self, ShapelyFeature, add_feature_method): ax = GeoAxes(plt.figure(), [0, 0, 1, 1], map_projection=ccrs.Robinson()) ax.add_geometries(mock.sentinel.geometries, mock.sentinel.crs, styler=mock.sentinel.styler, wibble='wobble') ShapelyFeature.assert_called_once_with( mock.sentinel.geometries, mock.sentinel.crs, wibble='wobble') add_feature_method.assert_called_once_with( ShapelyFeature(), styler=mock.sentinel.styler)
def test_gridliner_specified_lines(): xs = [0, 60, 120, 180, 240, 360] ys = [-90, -60, -30, 0, 30, 60, 90] ax = mock.Mock(_gridliners=[], spec=GeoAxes) gl = GeoAxes.gridlines(ax, xlocs=xs, ylocs=ys) assert isinstance(gl.xlocator, mticker.FixedLocator) assert isinstance(gl.ylocator, mticker.FixedLocator) assert gl.xlocator.tick_values(None, None).tolist() == xs assert gl.ylocator.tick_values(None, None).tolist() == ys
def test_gridliner_specified_lines(): xs = [0, 60, 120, 180, 240, 360] ys = [-90, -60, -30, 0, 30, 60, 90] ax = mock.Mock(_gridliners=[], spec=GeoAxes) gl = GeoAxes.gridlines(ax, xlocs=xs, ylocs=ys) assert isinstance(gl.xlocator, mticker.FixedLocator) assert isinstance(gl.ylocator, mticker.FixedLocator) assert gl.xlocator.tick_values(None, None).tolist() == xs assert gl.ylocator.tick_values(None, None).tolist() == ys
def test_gridliner_specified_lines(): meridians = [0, 60, 120, 180, 240, 360] parallels = [-90, -60, -30, 0, 30, 60, 90] ax = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree()) gl = GeoAxes.gridlines(ax, xlocs=meridians, ylocs=parallels) assert isinstance(gl.xlocator, mticker.FixedLocator) assert isinstance(gl.ylocator, mticker.FixedLocator) assert gl.xlocator.tick_values(None, None).tolist() == meridians assert gl.ylocator.tick_values(None, None).tolist() == parallels
def test_gridliner_specified_lines(): meridians = [0, 60, 120, 180, 240, 360] parallels = [-90, -60, -30, 0, 30, 60, 90] def mpl_connext(*args): pass canvas = mock.Mock(mpl_connext=mpl_connext) fig = mock.Mock(spec=matplotlib.figure.Figure, canvas=canvas) ax = mock.Mock(_gridliners=[], spec=GeoAxes, figure=fig) gl = GeoAxes.gridlines(ax, xlocs=meridians, ylocs=parallels) assert isinstance(gl.xlocator, mticker.FixedLocator) assert isinstance(gl.ylocator, mticker.FixedLocator) assert gl.xlocator.tick_values(None, None).tolist() == meridians assert gl.ylocator.tick_values(None, None).tolist() == parallels
def test_single_geometry(self): # A single geometry is acceptable proj = ccrs.PlateCarree() ax = GeoAxes(plt.figure(), [0, 0, 1, 1], map_projection=proj) ax.add_geometries(next(cfeature.COASTLINE.geometries()), crs=proj)