我正在尝试制作北美的基本地图,但我无法弄清楚如何使海岸线的线宽和行政边界变小。似乎没有内置选项。有一个简单的工作吗?以下是我的代码。
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)
答案 0 :(得分:3)
可以使用add_feature()
关键字控制这些行的宽度(或linewidth
方法添加的任何行)。默认线宽为1,使用较小的数字将产生较细的线:
ax.add_feature(cfeature.BORDERS, linewidth=0.5)
答案 1 :(得分:0)
地图的轮廓线是 ax.outline_patch 方法的一部分。如此处所述:
https://scitools.org.uk/cartopy/docs/latest/matplotlib/geoaxes.html
https://github.com/SciTools/cartopy/issues/1077
使用以下版本的修改版本:
https://matplotlib.org/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch
工作代码示例:
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(':')