我用NaturalEarth创建了一个带有国界的Stamen地形图。现在我想从国界之外删除所有数据(在这种情况下是地形)。我该怎么做?
以下是我的示例,瑞士内外可见地形:
以下是我的示例,瑞士内外可见地形:
from cartopy.io import shapereader
import cartopy.io.img_tiles as cimgt
import cartopy.crs as ccrs
import geopandas
import matplotlib.pyplot as plt
resolution = '10m'
category = 'cultural'
name = 'admin_0_countries'
shpfilename = shapereader.natural_earth(resolution, category, name)
df = geopandas.read_file(shpfilename)
poly = [df.loc[df['ADMIN'] == 'Switzerland']['geometry'].values[0]]
stamen_terrain = cimgt.Stamen('terrain-background')
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(1, 1, 1, projection=stamen_terrain.crs)
ax.add_geometries(poly, crs=ccrs.PlateCarree(), facecolor='none', edgecolor='r')
exts = [poly[0].bounds[0], poly[0].bounds[2], poly[0].bounds[1], poly[0].bounds[3]]
ax.set_extent(exts, crs=ccrs.Geodetic())
ax.add_image(stamen_terrain, 8)
fig.tight_layout()
plt.show()
如何只显示边界内的地形,其余区域呈白色/透明?
尝试过以下方法,但目前没有成功: https://scitools.org.uk/cartopy/docs/latest/gallery/logo.html