8

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:

enter image description here

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!

wotaskd
  • 925
  • 1
  • 10
  • 15
  • 1
    Possible duplicate of [Elegantly changing the color of a plot frame in matplotlib](http://stackoverflow.com/questions/7778954/elegantly-changing-the-color-of-a-plot-frame-in-matplotlib) – MB-F Feb 16 '16 at 09:18
  • Thanks. That is a potential solution for cases where each edge has to be customized. I was hoping that I could get it done in as few lines of code as possible, and added that clarification. – wotaskd Feb 16 '16 at 15:03

1 Answers1

11

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.

Daniel Kirkham
  • 379
  • 2
  • 3