我从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)
我想在补丁中心添加一个数字,即i
。我怎样才能做到这一点?