[Python] How to build a correct cartopy feature around the south pole?

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I want to build a cartopy feature for Antartica in palaeo geography. I have the lon/lat of the coastline.

    I cant find a way to have a nice plot in any projection.

    Here is an example that plot a simple circle (filled) around the south pole. It gives an ugly result in some projection.

    Is there a trick to make this work?

    import numpy as np
    import matplotlib.pyplot as plt, matplotlib as mpl
    import cartopy.crs as ccrs, cartopy
    import shapely as shp

    # Defines a circle around Antartica
    nn = 20
    lon_coast = np.linspace (start=-180, stop=180, num=nn)
    lat_coast = np.ones (nn)*(-70)
    coord_coast = np.stack ( [lon_coast, lat_coast] ).T

    coord_coast = np.vstack ( [coord_coast, np.array([np.nan, np.nan])])

    # Build the cartopy feature for the circle
    coast_shp = shp.Polygon (coord_coast)
    coast_feat = cartopy.feature.ShapelyFeature (coast_shp, ccrs.PlateCarree (central_longitude=0), facecolor='green')

    # Plot the circle with various projections
    fig = plt.figure(figsize=(12,8) )

    def my_fig (idx, proj) :
    pos=230+idx
    ax = fig.add_subplot (pos, projection=proj)
    ax.add_feature (coast_feat, facecolor='green', edgecolor='red')
    ax.coastlines ()
    ax.gridlines ()

    my_fig (1, ccrs.PlateCarree ())
    my_fig (2, ccrs.Orthographic (central_latitude=-90))
    my_fig (3, ccrs.PlateCarree (central_longitude=180))
    my_fig (4, ccrs.Robinson (central_longitude=0))
    my_fig (5, ccrs.Robinson (central_longitude=0))
    #my_fig (6, ccrs.Stereographic(central_latitude=-90))

    Continue reading...

Compartilhe esta Página