I am trying to plot interpolated weather data on a map only within the bounds of the towns contained in a shapefile. The following is the unclipped contourf over the Basemap with imported shapefile: Contourf overlaid on Basemap with Shapefile
I have tried clipping to contour collections by iterating through the contour collections like so:
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)
This obviously confines the contour to one polygon, i.e. one town, like this: Contourf clipped to one ploygon
Is it possible to create a collection of contour collections which I can then add by using ax.add_collection(new_contour_collection)? Something along the lines of:
for poly in patches:
for collection in cs.collections:
contour_collection.append(collection)
ax.add_collection(contour_collection)
Or can I create a single path from the Patchcollection and then clip each of the contour collections using collection.set_clip_patch(patches)?

contourfat lowerzorder. Then plot filled polygons with higherzorderto hide un-wanted parts ofcontourf. - swatchai