c['geometry']
is a series comprised of shapely.geometry.polygon.Polygon
objects. You can verify this by checking
In [23]: type(c.ix[23, 'geometry'])
Out[23]: shapely.geometry.polygon.Polygon
From the Shapely docs there is a method representative_point()
that
Returns a cheaply computed point that is guaranteed to be within the
geometric object.
Sounds ideal for a situation in which you need to label the polygon objects! You can then create a new column for your geopandas
dataframe
, 'coords'
like so
c['coords'] = c['geometry'].apply(lambda x: x.representative_point().coords[:])
c['coords'] = [coords[0] for coords in c['coords']]
Now that you have a set of coordinates pertaining to each polygon object (each county), you can annotate your plot by iterating through your dataframe
c.plot()
for idx, row in c.iterrows():
plt.annotate(s=row['NAME'], xy=row['coords'],
horizontalalignment='center')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…