I have a geodataframe 'all_locations' with a geometry column and a column with the name of the point. Plotting the points on a map works just fine but I want to annotate the points with location name.
['location'] ['geometry']
BUITHVN8 POINT()
(Actual dataframe is much larger of course)
I have tried this (and other things):
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'])
Adding a coordinates column but it gives this error: ''Point' object has no attribute 'point'
Using the cities
example dataset included in geopandas, you can do this as follows:
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With