【问题标题】:Shape disappears after changing the CCRS更改 CCRS 后形状消失
【发布时间】:2021-10-29 01:23:13
【问题描述】:

跟随another Q&A,我正在地球球上绘制非洲大陆的国家:

import cartopy
import cartopy.crs as ccrs
from matplotlib import pyplot as plt

import geopandas as gpd

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
africa = world[(world['continent'] == 'Africa')]

latlon_proj = ccrs.PlateCarree()
axis_proj = ccrs.Mollweide()

ax = plt.axes(projection=axis_proj)
ax.stock_img()

for ea in africa['geometry']:
    
    feat = cartopy.feature.ShapelyFeature(
        [ea],
        latlon_proj,
        facecolor="lime",
        edgecolor='black',
        lw=0.2
        )
    
    ax.add_feature(feat)

plt.show()

但是,当我将latlon_projaxis_proj 更改为ccrs.Orthographic() 时,非洲大陆消失了:

import cartopy
import cartopy.crs as ccrs
from matplotlib import pyplot as plt

import geopandas as gpd

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
africa = world[(world['continent'] == 'Africa')]

latlon_proj = ccrs.Orthographic()
axis_proj = ccrs.Orthographic()

ax = plt.axes(projection=axis_proj)
ax.stock_img()

for ea in africa['geometry']:
    
    feat = cartopy.feature.ShapelyFeature(
        [ea],
        latlon_proj,
        facecolor="lime",
        edgecolor='black',
        lw=0.2
        )
    
    ax.add_feature(feat)

plt.show()

更改CCRS时如何保留非洲大陆?

【问题讨论】:

    标签: geopandas cartopy


    【解决方案1】:

    代码中有错误使用 CRS。这是它的正确版本。

    import cartopy
    import cartopy.crs as ccrs
    from matplotlib import pyplot as plt
    
    import geopandas as gpd
    
    world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
    africa = world[(world['continent'] == 'Africa')]
    
    latlon_proj = ccrs.PlateCarree()  ## The correct CRS
    axis_proj = ccrs.Orthographic()
    
    ax = plt.axes(projection=axis_proj)
    ax.stock_img()
    
    for ea in africa['geometry']:
    
        feat = cartopy.feature.ShapelyFeature(
            [ea],
            latlon_proj,
            facecolor="lime",
            edgecolor='black',
            lw=0.2
            )
    
        ax.add_feature(feat)
    
    plt.show()
    

    【讨论】:

    • latlon_proj = ccrs.PlateCarree() 用于表示使用数据的坐标系。 axis_proj = ccrs.Orthographic() 用于表示要在绘图上使用的地图投影。
    • 太好了,谢谢。我想我必须研究两者的确切含义。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-23
    • 2019-02-11
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    相关资源
    最近更新 更多