改变 Cartopy 边框的线宽
Changing line width of Cartopy borders
我想画一张北美的基本地图,但我不知道如何把海岸线和行政边界的线宽变小。似乎没有内置选项。有一个简单的解决方法吗?下面是我到目前为止的代码。
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)
这些线(或任何由 add_feature()
方法添加的线)的宽度可以使用 linewidth
关键字来控制。默认线宽为 1,使用较小的数字将产生较细的线:
ax.add_feature(cfeature.BORDERS, linewidth=0.5)
地图的轮廓是 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(':')
我想画一张北美的基本地图,但我不知道如何把海岸线和行政边界的线宽变小。似乎没有内置选项。有一个简单的解决方法吗?下面是我到目前为止的代码。
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)
这些线(或任何由 add_feature()
方法添加的线)的宽度可以使用 linewidth
关键字来控制。默认线宽为 1,使用较小的数字将产生较细的线:
ax.add_feature(cfeature.BORDERS, linewidth=0.5)
地图的轮廓是 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(':')