Geopandas - 地图和位置绘图

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

由于这个question的答案,我可以绘制地图和世界地图与大陆和海洋颜色在不同的投影。

现在我想补充一点,例如包括在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)

结果如下:

enter image description here

python geopandas cartopy
1个回答
1
投票

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的所有其他特征之上。

即使r:r:r zxsw

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