J-m*_*man 8 python-3.x geopandas
我有一个带有几何列和带有点名称的列的地理数据框“all_locations”。在地图上绘制点效果很好,但我想用位置名称注释点。
['位置'] ['几何']
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'])
Run Code Online (Sandbox Code Playgroud)
添加坐标列但它给出了这个错误:“点”对象没有属性“点”
jor*_*ris 18
使用cities
geopandas 中包含的示例数据集,您可以执行以下操作:
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")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7585 次 |
最近记录: |