Python使用投影gcrs.albersqualarea()在geoplot.choropleth.map图形上添加标签

2024-05-15 08:04:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在绘制一张choropleth地图,每个区域的名称都在多边形上。当我移除投影线时,效果很好,但贴图是水平拉伸的。当我使用projection=gcrs.albersqualarea()时,我消除了拉伸,但这次所有标签在中心重叠。有人知道是什么导致了这个问题吗?如何使标签显示在具有未拉伸投影的多边形上

ax = gplt.choropleth(df=map_data,
                projection=gcrs.AlbersEqualArea(),
               hue='population',
               figsize=(16,8),
               legend=True,
                cmap='BuGn',
                scheme=scheme_2,
                legend_kwargs={'loc': 'lower right'},
                edgecolor='black', linewidth=0.5,

)
map_data.apply(lambda x: ax.annotate(s=x.population_abb, xy=x.geometry.centroid.coords[0],fontsize='x-small',fontstretch='ultra-expanded',  ha='center',bbox={'facecolor': 'white', 'alpha':0.3, 'pad': 2, 'edgecolor':'none'}),axis=1,);

地图:

enter image description here


Tags: mapdata地图绘制标签ax多边形投影