I am trying to make a basic map of North America, but I cannot figure out how to make the line width of the coastline and the administrative border smaller. There does not seem to be a built in option for this. Is there an easy work around? Below is my code thus far.
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import cartopy.crs as ccrs
east = -63
west = -123
north = 55
south = 20
fig = plt.figure()
ax=fig.add_subplot(1,1,1,projection=ccrs.AlbersEqualArea)
ax.set_extent([west, east, south, north])
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.LAND,color='grey')
ax.add_feature(cfeature.BORDERS)
ax.add_feature(cfeature.COASTLINE)
The widths of these lines (or any lines added by the add_feature()
method) can be controlled using the linewidth
keyword. The default line width is 1, using a smaller number willl produce thinner lines:
ax.add_feature(cfeature.BORDERS, linewidth=0.5)
The outline for your map is part of the ax.outline_patch method. As mentioned here:
https://scitools.org.uk/cartopy/docs/latest/matplotlib/geoaxes.html
https://scitools.org.uk/cartopy/docs/latest/matplotlib/geoaxes.html#cartopy.mpl.geoaxes.GeoAxes.outline_patch
https://github.com/SciTools/cartopy/issues/1077
using a modified version of:
https://matplotlib.org/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch
Working code example:
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import cartopy.crs as ccrs
east = -63
west = -123
north = 55
south = 20
fig = plt.figure()
ax = plt.subplot(1,1,1, projection=ccrs.AlbersEqualArea())
ax.set_extent([west, east, south, north])
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.LAND,color='grey')
ax.add_feature(cfeature.BORDERS)
ax.add_feature(cfeature.COASTLINE)
#Add your line modifications here
ax.outline_patch.set_linewidth(5)
ax.outline_patch.set_linestyle(':')
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