备注
Go to the end 下载完整的示例代码。
特征创建#
此示例手动实例化 cartopy.feature.NaturalEarthFeature
访问行政边界(州和省)。
请注意,此示例旨在说明构建Cartopy不一定了解的自然地球特征的能力 a priori .然而,在这种情况下,可以使用预定义的 cartopy.feature.STATES
常数

from matplotlib.offsetbox import AnchoredText
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
def main():
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([80, 170, -45, 30], crs=ccrs.PlateCarree())
# Put a background image on for nice sea rendering.
ax.stock_img()
# Create a feature for States/Admin 1 regions at 1:50m from Natural Earth.
states_provinces = cfeature.NaturalEarthFeature(
category='cultural',
name='admin_1_states_provinces_lines',
scale='50m',
facecolor='none')
SOURCE = 'Natural Earth'
LICENSE = 'public domain'
# Add our states feature.
ax.add_feature(states_provinces, edgecolor='gray')
# Add land feature, overriding the default negative zorder so it shows
# above the background image.
ax.add_feature(cfeature.LAND, zorder=1, edgecolor='k')
# Add a text annotation for the license information to the
# the bottom right corner.
text = AnchoredText('\u00A9 {}; license: {}'
''.format(SOURCE, LICENSE),
loc=4, prop={'size': 12}, frameon=True)
ax.add_artist(text)
plt.show()
if __name__ == '__main__':
main()
Total running time of the script: (0分0.174秒)
Gallery generated by Sphinx-Gallery
_