Python:如何在绘制来自shapefile的地理边界时在补丁上显示文本?

时间:2018-10-17 09:38:44

标签: python matplotlib patch shapefile

我从Open Swiss Data网站下载了瑞士邮政编码边界的shapefile。

##  Boundaries Shapefile
sf = shapefile.Reader("Data/PLZO_SHP_LV95/zips.shp")
recs    = sf.records()
shapes  = sf.shapes()
Nshp    = len(shapes)

我正在绘制邮政编码区域的边界。

fig,ax = plt.subplots(figsize=(10,7.5))
for label in (ax.get_xticklabels() + ax.get_yticklabels()):
    label.set_fontname('Arial')
    label.set_fontsize(16)

for i, nshp in enumerate(xrange(Nshp)):

    pts     = array(shapes[nshp].points)
    prt     = shapes[nshp].parts
    par     = list(prt) + [pts.shape[0]]
    bbPath = mplPath.Path(pts)
    ptchs   = []
    color = 'white'
    for pij in xrange(len(prt)):
        ptchs.append(Polygon(pts[par[pij]:par[pij+1]]))
        p = PatchCollection(ptchs,facecolor = color, edgecolor='k', linewidths = 2)
        ax.add_collection(PatchCollection(ptchs, facecolor= color,edgecolor='darkgray', 
                                              linewidths = 1,alpha=.7))
    ax.set_xlim(8.446, 8.63)
    ax.set_ylim(47.319,47.436)

enter image description here

我想在补丁中心添加一个数字,即i。我怎样才能做到这一点?

0 个答案:

没有答案