Geopandas世界地图的极地立体投影 [英] Polar Stereographic projection of geopandas world map
问题描述
我想使用包含地理熊猫的低分辨率世界地图(请参见此处)作为背景我的数据.只要我使用例如"PlateCarree"投影.
I want to use the geopandas included low resolution world map (see here) as a background for my data. This works fine as long as I use e.g. 'PlateCarree' projection.
如果我现在想使用极地立体影像学
If I now want to use a polar stereographic peojection
ccrs.NorthPolarStereo()
或
ccrs.SouthPolarStereo()
它不起作用.
我的代码如下(使用python 3)
My code looks like this (using 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',)
知道极地立体投影根本无法在此地图上工作(如果是,为什么呢?)还是我做错了什么?
Any idea if polar stereographic projections simply do not work for this map (if so why?) or am I doing something wrong?
推荐答案
当使用特定的Cartopy投影进行绘图时,最好实际使用Cartopy创建matplotlib图形和轴,以确保它了解投影(在技术术语:要确保它是GeoAxes
,请参见 https: //scitools.org.uk/cartopy/docs/latest/matplotlib/intro.html ):
When plotting with a specific cartopy projection, it is best to actually create the matplotlib figure and axes using cartopy, to make sure it is aware of the projection (in technical terms: to make sure it is a GeoAxes
, see 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
方法,可以更好地考虑范围:
However, this still seems to plot the shapes that fall outside of the extent. Using the cartopy add_geometries
method, this better respects the extent:
fig, ax = plt.subplots(subplot_kw=dict(projection=crs))
ax.add_geometries(w['geometry'], crs=crs, facecolor='sandybrown', edgecolor='black')
乍一看,这看起来有些奇怪(中间的南极洲很小),但这似乎是可以预期的(请参见
This looks a bit strange at first sight (Antartica in the middle is very small), but this seems to be expected (see https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#southpolarstereo).
通常,请参见文档中有关结合GeoPandas和cartopy的示例: https://geopandas.readthedocs.io/en/latest/gallery/cartopy_convert.html
In general, see the example on combining GeoPandas and cartopy in the docs: https://geopandas.readthedocs.io/en/latest/gallery/cartopy_convert.html
这篇关于Geopandas世界地图的极地立体投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!