Geopandas - 地图和位置绘图

Geopandas - map and locaton plotting

感谢这个 的答案,我可以绘制 geopandas 世界地图,其中大陆和海洋以不同的投影着色。

现在我想补充几点,例如geopandas 中包含的城市

cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))

不幸的是,城市被充满的大陆所覆盖。有没有办法让这些城市在地图的前面或顶部?

我当前的代码如下所示:

facecolor = 'sandybrown'
edgecolor = 'black'
ocean_color = '#A8C5DD'

crs1 = ccrs.NorthPolarStereo()

world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))

w1 = world.to_crs(crs1.proj4_init)
c1 = cities.to_crs(crs1.proj4_init)

fig1, ax1 = plt.subplots(figsize=(7,7), subplot_kw={'projection': crs1})

# useful code to set map extent,
# --- if you want maximum extent, comment out the next line of code ---
ax1.set_extent([-60.14, 130.4, -13.12, -24.59], crs=ccrs.PlateCarree())

# at maximum extent, the circular bound trims map features nicely
ax1.add_geometries(w1['geometry'], crs=crs1, facecolor=facecolor, edgecolor=edgecolor, linewidth=0.5)

# this adds the ocean coloring
ax1.add_feature(cartopy.feature.OCEAN, facecolor=ocean_color, edgecolor='none')

# this adds the cities
c1.plot(ax=ax1, marker='o', color='red', markersize=50)

结果如下所示:

axes 的默认绘图顺序是补丁、线条、文本。此顺序由 zorder 属性确定。

Polygon/patch,  zorder=1
Line 2D,  zorder=2
Text,  zorder=3

您可以通过设置 zorder 来更改各个地图功能的顺序。 任何单独的 plot() 调用都可以为该特定项目的 zorder 设置一个值。

在您的情况下,代码

c1.plot(ax=ax1, marker='o', color='red', markersize=50, zorder=20)

将在 zorder 小于 20 的所有其他特征之上绘制标记。

Zorder 演示:https://matplotlib.org/gallery/misc/zorder_demo.html