【问题标题】:Annotate a geoplot when using a projection使用投影时注释地理图
【发布时间】:2021-09-14 07:18:48
【问题描述】:

我得到了一个数据框,其中包含以下列名称(字符串)、大小(num)、纬度(num)、经度(num)、几何(shapely.geometry.point.Point)。

当我在地图上绘制我的点并尝试注释每个点时,根本不会显示注释。我的猜测是这是由于我使用的投影。

这是我正在运行的代码行:

import geopandas as gpd
import geoplot as gplt

proj = gplt.crs.AlbersEqualArea()
fig, ax = plt.subplots(figsize=(10, 10), subplot_kw={'projection': proj})

gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.longitude, df.latitude))
gplt.pointplot(gdf, hue='size', s=15, ax=ax, cmap=palette, legend=True, zorder=10)
for idx, row in gdf.iterrows():
    plt.annotate(s=row['Name'], xy=[row['latitude'],row['longitude']])
plt.show()

【问题讨论】:

    标签: geopandas annotate geoplot


    【解决方案1】:

    你需要坐标变换

    plt.annotate(s=row['Name'], xy=[row['latitude'],row['longitude']])
    

    变换应该是

    xtran = gplt.crs.ccrs.AlbersEqualArea()
    

    将该行替换为

    x, y = xtran.transform_point(row['longitude'], row['latitude'], ccrs.PlateCarree())
    plt.annotate( s=row['Name'], xy=[x, y] )
    

    【讨论】:

      猜你喜欢
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      • 2012-06-08
      • 2021-09-28
      • 2020-12-19
      • 2017-07-24
      相关资源
      最近更新 更多