2

我得到了一个包含以下列名称(字符串)、大小(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()
4

1 回答 1

0

你需要坐标变换

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] )
于 2021-09-14T12:51:48.737 回答