极地立体投影与彩色海洋的Geopandas世界地图 [英] Geopandas world map in Polar Stereographic projection with coloured oceans

查看:164
本文介绍了极地立体投影与彩色海洋的Geopandas世界地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此问题添加更多要求,我还需要使海洋变成蓝色(或其他任何颜色).

Adding a further requirement to this question, I also need to have the oceans in blue (or any other colour).

对于"PlateCarree"投影,我可以简单地做到这一点

For the 'PlateCarree' projection I can simply do this

crs = ccrs.PlateCarree()
crs_proj4 = crs.proj4_init
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
w = world.to_crs(crs_proj4)
g = w.plot(facecolor='sandybrown', edgecolor='black')

现在添加海洋的颜色

g.set_facecolor('#A8C5DD')

如果我现在想使用极地立体影像学

If I now want to use a polar stereographic peojection

ccrs.NorthPolarStereo()

ccrs.SouthPolarStereo()

该投影不起作用.将答案应用于问题时,我无法使海洋变成彩色

the projection does not work. When applying the answer to this question, I cannot get the oceans coloured

推荐答案

您需要在Cartopy geoaxes上绘制地图几何图形,并使用cartopy.feature.OCEAN绘制海洋.这是您可以尝试的工作代码.阅读代码中的注释以进行澄清.

You need to plot the map geometries on Cartopy geoaxes, and use cartopy.feature.OCEAN to plot the ocean. Here is the working code that you may try. Read the comments in the code for clarification.

import geopandas as gpd
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy

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

#crs1 = ccrs.SouthPolarStereo()
crs1 = ccrs.NorthPolarStereo()

world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
w1 = world.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')

plt.show()

输出图将是:

这篇关于极地立体投影与彩色海洋的Geopandas世界地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆