如何使用 Cartopy 绘制非洲地图
我们可以通过将范围设置为 [-23, 55, -35, 40] 轻松使用 Cartopy 绘制非洲地图:
how-to-draw-africa-map-using-cartopy.py
ax.set_extent([-23, 55, -35, 40])完整代码示例
上面的代码生成上面显示的图像:
africa_cartopy_complete.py
import cartopy.crs as ccrs
import cartopy.feature as cf
from matplotlib import pyplot as plt
proj = ccrs.PlateCarree()
ax = plt.axes(projection=proj)
ax.set_extent([-23, 55, -35, 40])
ax.stock_img()
ax.add_feature(cf.COASTLINE, lw=2)
ax.add_feature(cf.BORDERS)
# 使图更大
plt.gcf().set_size_inches(20, 10)
# 将图保存为 SVG
plt.savefig("Africa.svg")If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow