Geopandas 为地块上的点添加标签
Geopandas add labels to points on plot
我有一个地理数据框 'all_locations',其中包含一个几何列和一个包含点名称的列。在地图上绘制点很好用,但我想用位置名称注释这些点。
['location'] ['geometry']
BUITHVN8 点()
(当然,实际数据框要大得多)
我试过这个(和其他东西):
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' object has no attribute '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")
我有一个地理数据框 'all_locations',其中包含一个几何列和一个包含点名称的列。在地图上绘制点很好用,但我想用位置名称注释这些点。
['location'] ['geometry']
BUITHVN8 点()
(当然,实际数据框要大得多)
我试过这个(和其他东西):
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' object has no attribute '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")