Reputation: 5075
I have seen this question where labels are added to polygons and they appear inside each polygon. I am trying to accomplish the same thing, but I am using a different format and can´t see how to apply the same method to my case.
My polygons are like this:
import geopandas as gpd
from shapely.geometry import Polygon
boundary = gpd.GeoSeries({
'foo': Polygon([(5, 5), (5, 13), (13, 13), (13, 5)]),
'bar': Polygon([(20, 20), (40, 20), (40, 30), (20, 30)]),
})
boundary.plot(cmap="Greens")
plt.show()
Any idea how to make each polygon have a label?
Upvotes: 2
Views: 3560
Reputation: 2287
One approach might be to use the centroids from your polygons and annotate:
ax = boundary.plot(cmap="Greens")
for i, geo in boundary.centroid.iteritems():
ax.annotate(s=i, xy=[geo.x, geo.y], color="red")
# show the subplot
ax.figure
plt.show()
Upvotes: 4