[英]Geopandas world map in Polar Stereographic projection with coloured oceans
[英]Polar Stereographic projection of geopandas world map
我想使用 geopandas 包含的低分辨率世界地图(见这里)作为我的数据的背景。 只要我使用例如“PlateCarree”投影,这就可以正常工作。
如果我现在想使用极坐标立体投影
ccrs.NorthPolarStereo()
或者
ccrs.SouthPolarStereo()
这是行不通的。
我的代码看起来像这样(使用 python 3)
import geopandas as gpd
import cartopy.crs as ccrs
crs = ccrs.NorthPolarStereo()
crs_proj4 = crs.proj4_init
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
w = world.to_crs(crs_proj4)
w.plot(facecolor='sandybrown', edgecolor='black',)
知道极地立体投影是否根本不适用于这张地图(如果是,为什么?)还是我做错了什么?
使用特定的 cartopy 投影进行绘图时,最好使用 cartopy 实际创建 matplotlib 图形和轴,以确保它知道投影(在技术术语中:确保它是GeoAxes
,请参阅https://scitools .org.uk/cartopy/docs/latest/matplotlib/intro.html ):
crs = ccrs.SouthPolarStereo()
crs_proj4 = crs.proj4_init
w = world.to_crs(crs_proj4)
fig, ax = plt.subplots(subplot_kw=dict(projection=crs))
w.plot(ax=ax, facecolor='sandybrown', edgecolor='black')
然而,这似乎仍然绘制了超出范围的形状。 使用 cartopy add_geometries
方法,这更好地尊重范围:
fig, ax = plt.subplots(subplot_kw=dict(projection=crs))
ax.add_geometries(w['geometry'], crs=crs, facecolor='sandybrown', edgecolor='black')
这乍一看有点奇怪(中间的南极洲很小),但这似乎是意料之中的(参见https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#southpolarstereo ) .
一般来说,请参阅文档中关于结合 GeoPandas 和 cartopy 的示例: https ://geopandas.readthedocs.io/en/latest/gallery/cartopy_convert.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.