在使用投影时注释geoplot



我得到了一个包含以下列的数据框名称(字符串),大小(num),纬度(num),经度(num),几何形状(shape .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()

需要坐标变换
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] )

最新更新