I'm plotting a world map in Cartopy and as part of the process I want to color all lines white. I have been able to do so for every element with exception of the map's boundaries. This is the code I'm using:
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)
And this is the final result:
Any idea of how to change the boundary line to either white or to turn it off completely, in as few steps as possible?
Thanks!
It is possible to make the frame white with the following line:
ax.outline_patch.set_edgecolor('white')
As an aside, plt.axes
accepts a boolean keyword argument frameon
, which, when set to False
, prevents drawing the border. However, it appears to be ignored by Cartopy. This is a potential bug which should be looked into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With