【发布时间】:2016-05-27 04:32:54
【问题描述】:
我正在 Cartopy 中绘制世界地图,作为该过程的一部分,我想将所有线条都涂成白色。除了地图的边界外,我已经能够对每个元素都这样做。这是我正在使用的代码:
import matplotlib.pyplot as plt
import cartopy
import cartopy.io.shapereader as shpreader
import cartopy.crs as ccrs
fig = plt.Figure()
fig.set_canvas(plt.gcf().canvas)
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_feature(cartopy.feature.LAND, linewidth=0.5, edgecolor='white')
ax.set_extent([-150,60,-25,60])
shpf = shpreader.natural_earth(resolution='110m', category='cultural', name='admin_0_countries')
reader = shpreader.Reader(shpf)
countries = reader.records()
for country in countries:
ax.add_geometries(country.geometry, ccrs.PlateCarree(), facecolor=(0,1,0), linewidth=0.5, edgecolor='white', label=country.attributes['adm0_a3'])
fig.savefig("final_image.png", format='png', dpi=200)
这是最终的结果:
知道如何以尽可能少的步骤将边界线更改为白色或完全关闭它吗?
谢谢!
【问题讨论】:
-
谢谢。对于必须定制每个边缘的情况,这是一个潜在的解决方案。我希望我可以用尽可能少的代码行来完成它,并添加了说明。
标签: python matplotlib cartopy