Search code examples
pythongeopandascartopy

Polar Stereographic projection of geopandas world map


I want to use the geopandas included low resolution world map (see here) as a background for my data. This works fine as long as I use e.g. 'PlateCarree' projection.

If I now want to use a polar stereographic peojection

ccrs.NorthPolarStereo()

or

ccrs.SouthPolarStereo()

It does not work.

My code looks like this (using python 3)

import geopandas as gpd
import cartopy.crs as ccrs

crs = ccrs.NorthPolarStereo()
crs_proj4 = crs.proj4_init
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
w = world.to_crs(crs_proj4)
w.plot(facecolor='sandybrown', edgecolor='black',)

Any idea if polar stereographic projections simply do not work for this map (if so why?) or am I doing something wrong?


Solution

  • When plotting with a specific cartopy projection, it is best to actually create the matplotlib figure and axes using cartopy, to make sure it is aware of the projection (in technical terms: to make sure it is a GeoAxes, see https://scitools.org.uk/cartopy/docs/latest/matplotlib/intro.html):

    crs = ccrs.SouthPolarStereo()
    crs_proj4 = crs.proj4_init
    w = world.to_crs(crs_proj4)
    
    fig, ax = plt.subplots(subplot_kw=dict(projection=crs))
    w.plot(ax=ax, facecolor='sandybrown', edgecolor='black')
    

    However, this still seems to plot the shapes that fall outside of the extent. Using the cartopy add_geometries method, this better respects the extent:

    fig, ax = plt.subplots(subplot_kw=dict(projection=crs))
    ax.add_geometries(w['geometry'], crs=crs, facecolor='sandybrown', edgecolor='black')
    

    enter image description here

    This looks a bit strange at first sight (Antartica in the middle is very small), but this seems to be expected (see https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#southpolarstereo).

    In general, see the example on combining GeoPandas and cartopy in the docs: https://geopandas.readthedocs.io/en/latest/gallery/cartopy_convert.html