【问题标题】:Change map boundary color in Cartopy在 Cartopy 中更改地图边界颜色
【发布时间】: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


【解决方案1】:

可以使用以下行将框架设置为白色:

ax.outline_patch.set_edgecolor('white')

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

【讨论】:

  • 啊,打败我!你也可以使用ax.outline_patch.set_visible(False)
  • ax.spines['geo'].set_edgecolor('white')。您的解决方案已弃用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-12
  • 1970-01-01
  • 2014-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多