【问题标题】:add labels to polygons向多边形添加标签
【发布时间】:2018-12-18 01:46:11
【问题描述】:

I have seen this question 将标签添加到多边形并出现在每个多边形内。 我正在尝试完成同样的事情,但我使用了不同的格式,无法看到如何将相同的方法应用于我的案例。

我的多边形是这样的:

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

知道如何让每个多边形都有标签吗?

【问题讨论】:

    标签: python-3.x shapely geopandas


    【解决方案1】:

    一种方法可能是使用多边形的质心并进行注释:

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

    【讨论】:

      猜你喜欢
      • 2014-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-18
      • 2021-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多