【发布时间】:2019-09-05 09:10:31
【问题描述】:
感谢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)
结果如下:
【问题讨论】:
-
使用
zorder,例如:c1.plot(ax=ax1, marker='o', color='red', markersize=50, zorder=20)应该把所有的点都放在前面。 -
可以这么简单:)。这成功了。谢谢。