我试图仅在shapefile中包含的城镇范围内在 Map 上绘制插值天气数据 . 以下是使用导入的shapefile在Basemap上的未剪切的contourf:Contourf overlaid on Basemap with Shapefile

我已经尝试通过遍历轮廓集来剪切到轮廓集合,如下所示:

m.readshapefile('data/grense', 'grense',zorder=10,linewidth=1, 
drawbounds=True)

patches   = []
for info, shape in zip(m.grense_info, m.grense):
   patches.append( Polygon(np.array(shape), linestyle=':', fill=False) )

for poly in patches:
   for collection in cs.collections:
      collection.set_clip_path(poly)

这显然将轮廓限制在一个多边形,即一个城镇,如下所示:Contourf clipped to one ploygon

是否可以创建一个轮廓集合的集合,然后我可以使用ax.add_collection(new_contour_collection)添加它?有点像:

for poly in patches:
   for collection in cs.collections:
     contour_collection.append(collection)
ax.add_collection(contour_collection)

或者我可以从Patchcollection创建单个路径,然后使用collection.set_clip_patch(补丁)剪辑每个轮廓集合?