Geopandas-地图和地点绘图

时间:2019-04-15 11:32:12

标签: python geopandas cartopy

感谢对此question的回答,我可以绘制出带有不同投影颜色的大洲和海洋的大熊猫世界地图。

现在我想补充一点,例如地理大熊猫中的城市

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

1 个答案:

答案 0 :(得分: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的要素上绘制标记。

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

相关问题