cartopy stock_img
时间: 2023-07-21 12:32:22 浏览: 93
CartoPy中文介绍_cartopy_
5星 · 资源好评率100%
`cartopy` 是一个 Python 库,用于绘制地图和地理数据。`stock_img` 是 `cartopy` 中的一个模块,用于获取常用的地图背景图像。可以使用以下代码导入 `cartopy` 和 `stock_img` 模块:
```python
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.io import shapereader
import matplotlib.pyplot as plt
# 获取地图背景图像
land = cfeature.NaturalEarthFeature('physical', 'land', '110m',
edgecolor='face',
facecolor=cfeature.COLORS['land'])
ocean = cfeature.NaturalEarthFeature('physical', 'ocean', '110m',
edgecolor='face',
facecolor=cfeature.COLORS['water'])
lakes = cfeature.NaturalEarthFeature('physical', 'lakes', '110m',
edgecolor='face',
facecolor=cfeature.COLORS['water'])
rivers = cfeature.NaturalEarthFeature('physical', 'rivers_lake_centerlines', '110m',
edgecolor=cfeature.COLORS['water'],
facecolor='none')
# 绘制地图
fig = plt.figure(figsize=[10, 5])
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([73, 135, 18, 53], crs=ccrs.PlateCarree())
ax.add_feature(land, facecolor='gray')
ax.add_feature(ocean)
ax.add_feature(lakes)
ax.add_feature(rivers)
plt.show()
```
这段代码将绘制一个包含陆地、海洋、湖泊和河流的地图。你可以根据需要自定义地图背景。
阅读全文