Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing line width of Cartopy borders

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)
like image 850
jtam Avatar asked Apr 28 '17 03:04

jtam


2 Answers

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)
like image 90
ajdawson Avatar answered Nov 17 '22 15:11

ajdawson


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(':')
like image 1
Kenneth D Avatar answered Nov 17 '22 14:11

Kenneth D