边界和海岸线对Python Cartopy的干扰。

问题描述 投票:0回答:1

我想用Cartopy画一张法国地图,但我对它不是很适应。

在互联网上搜索Python代码,在这里和那里,我建立了以下程序。

import cartopy
import cartopy.feature as cfeature
import cartopy.crs as ccrs

import numpy as np

extent = [-4.25, 7.5, 42.25, 51]
central_lon = np.mean(extent[:2])
central_lat = np.mean(extent[2:])

plt.figure(figsize=(8, 8))

ax = plt.axes(projection=ccrs.AlbersEqualArea(central_lon, central_lat))

ax.set_extent(extent)
ax.gridlines()

rivers_50m = cfeature.NaturalEarthFeature('physical', 'rivers_lake_centerlines', '50m')

ax.add_feature(cartopy.feature.BORDERS, linestyle='-', alpha=1)
ax.add_feature(cartopy.feature.OCEAN,facecolor=("lightblue"))
ax.add_feature(cartopy.feature.LAND, edgecolor='black')
ax.add_feature(cartopy.feature.LAKES, edgecolor='black')
ax.add_feature(rivers_50m, facecolor='None', edgecolor='blue', linestyle=':')
ax.coastlines(resolution='10m', color='red', linestyle='-', alpha=1)

plt.show()

这导致了下面的地图:enter image description here

这几乎是我想要的,但是... ... 我不明白为什么原始的边界(深色的断线)会与海滨的海岸线(波浪形的红线)相互干扰,这真的很丑陋。

有什么办法可以补救呢?(知道我想保持陆地边界的原样)。

python-3.x matplotlib cartopy
1个回答
0
投票

这里是可运行的代码。现在绘制的所有特征都有相同的。scale 或分辨率。可用的尺度有。110m, 50m, 10m.

import matplotlib.pyplot as plt
import cartopy
import cartopy.feature as cfeature
import cartopy.crs as ccrs
import numpy as np

extent = [-4.25, 7.5, 42.25, 51]
central_lon = np.mean(extent[:2])
central_lat = np.mean(extent[2:])

plt.figure(figsize=(8, 8))

ax = plt.axes(projection=ccrs.AlbersEqualArea(central_lon, central_lat))
ax.set_extent(extent)
ax.gridlines()

resol = '50m'  # use data at this scale
bodr = cartopy.feature.NaturalEarthFeature(category='cultural', 
    name='admin_0_boundary_lines_land', scale=resol, facecolor='none', alpha=0.7)
land = cartopy.feature.NaturalEarthFeature('physical', 'land', \
    scale=resol, edgecolor='k', facecolor=cfeature.COLORS['land'])
ocean = cartopy.feature.NaturalEarthFeature('physical', 'ocean', \
    scale=resol, edgecolor='none', facecolor=cfeature.COLORS['water'])
lakes = cartopy.feature.NaturalEarthFeature('physical', 'lakes', \
    scale=resol, edgecolor='b', facecolor=cfeature.COLORS['water'])
rivers = cartopy.feature.NaturalEarthFeature('physical', 'rivers_lake_centerlines', \
    scale=resol, edgecolor='b', facecolor='none')

ax.add_feature(land, facecolor='beige')
ax.add_feature(ocean, linewidth=0.2 )
ax.add_feature(lakes)
ax.add_feature(rivers, linewidth=0.5)
ax.add_feature(bodr, linestyle='--', edgecolor='k', alpha=1)

plt.show()

而图。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.