Skip to content Skip to sidebar Skip to footer

Geopandas Add Labels To Points On Plot

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

Solution 1:

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")

Post a Comment for "Geopandas Add Labels To Points On Plot"