繁体   English   中英

Geopandas为地块上的点添加标签

[英]Geopandas add labels to points on plot

我有一个地理数据框'all_locations',带有几何列和一个带有点名称的列。 绘制地图上的点工作得很好,但我想用位置名称注释点。


['location'] ['几何']
BUITHVN8 POINT()

(实际数据帧当然要大得多)

我试过这个(和其他的东西):

    all_locations['coords'] = all_locations['geometry'].apply(lambda x: x.point.coords[:])
all_locations['coords'] = [coords[0] for coords in all_locations['coords']]

all_locations.plot(ax=ax)
for idx, row in all_locations.iterrows():
    plt.annotate(s=row['locatie'], xy=row['geometry'])

添加坐标列但会出现此错误:''Point'对象没有属性'point'

使用geopandas中包含的cities示例数据集,您可以执行以下操作:

import geopandas
cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))

ax = cities.plot()

for x, y, label in zip(cities.geometry.x, cities.geometry.y, cities.name):
    ax.annotate(label, xy=(x, y), xytext=(3, 3), textcoords="offset points")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM