【问题标题】:Geopandas world map in Polar Stereographic projection with coloured oceans彩色海洋极地立体投影中的 Geopandas 世界地图
【发布时间】:2019-04-12 12:16:16
【问题描述】:

question 增加进一步的要求,我还需要将海洋设为蓝色(或任何其他颜色)。

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

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')

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

ccrs.NorthPolarStereo()

ccrs.SouthPolarStereo()

投影不起作用。将答案应用于question 时,我无法为海洋着色

【问题讨论】:

    标签: python geopandas cartopy


    【解决方案1】:

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

    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()
    

    输出图将是:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-05
      • 2016-10-14
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多