目前没有 ShapefileFeature 类(虽然这很容易创建,并且可能很有意义)所以如果你真的想使用功能界面,那么有一个箍可以跳过:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io.shapereader import Reader
from cartopy.feature import ShapelyFeature
fname = '50m_glaciated_areas.shp'
ax = plt.axes(projection=ccrs.Robinson())
shape_feature = ShapelyFeature(Reader(fname).geometries(),
ccrs.PlateCarree(), facecolor='none')
ax.add_feature(shape_feature)
plt.show()
或者,您可以只使用 add_geometries 方法,该方法不使用功能接口(因此,将来不会优化为仅从磁盘读取实际正在绘制的几何图形,就像使用ShapefileFeature 类):
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io.shapereader import Reader
fname = '50m_glaciated_areas.shp'
ax = plt.axes(projection=ccrs.Robinson())
ax.add_geometries(Reader(fname).geometries(),
ccrs.PlateCarree(),
facecolor='white', hatch='xxxx')
plt.show()
高温高压