如何使 Cartopy 海岸线或边界线更粗(线宽)

默认情况下,Cartopy 以相同的线宽绘制每个特征:

cartopy_linewidth.py
ax.add_feature(cf.COASTLINE)
ax.add_feature(cf.BORDERS)

Cartopy 中具有标准线宽海岸线和边界的非洲地图我们可以通过在 ax.add_feature() 调用中添加例如 lw=2 轻松增加线宽:

cartopy_linewidth_complete.py
ax.add_feature(cf.COASTLINE, lw=2)
ax.add_feature(cf.BORDERS)

使用 lw=2 在 Cartopy 中具有更粗海岸线线宽的非洲地图

完整代码示例

此示例生成上面显示的具有更宽海岸线线宽的图像

cartopy_linewidth_save_example.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-Standard.svg")

Check out similar posts by category: Cartopy, Geography, Python