8

我正在 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)

这是最终的结果:

在此处输入图像描述

关于如何以尽可能少的步骤将边界线更改为白色或完全关闭它的任何想法?

谢谢!

4

1 回答 1

10

可以使用以下行使框架变为白色:

ax.outline_patch.set_edgecolor('white')

顺便说一句,plt.axes接受一个布尔关键字参数frameon,当设置为 时False,会阻止绘制边框。然而,它似乎被 Cartopy 忽略了。这是一个应该调查的潜在错误。

于 2016-02-16T09:25:11.130 回答