繁体   English   中英

Geopandas-地图和地点绘图

[英]Geopandas - map and locaton plotting

多亏了对这个问题的回答,我才能绘制出带有不同投影颜色的大洲和海洋的大熊猫世界地图。

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

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更改各个地图zorder 任何单独的plot()调用都可以为该特定项目的zorder设置一个值。

就您而言,代码

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

会将标记绘制在zorder小于20的所有其他zorder顶部。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM