【发布时间】:2018-12-10 03:23:25
【问题描述】:
我试图在地图上仅在 shapefile 中包含的城镇范围内绘制插值天气数据。以下是带有导入 shapefile 的 Basemap 上未剪裁的轮廓: 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(patches) 剪辑每个轮廓集合吗?
【问题讨论】:
-
如果您只想要可视化,请将您的
contourf绘制在较低的zorder处。然后用更高的zorder绘制填充多边形以隐藏contourf的不需要的部分。 -
看看this是否有帮助。
-
非常好的解决方案。请考虑将解决方案发布为您自己问题的答案并接受它。这样其他人就会看到您的问题不需要进一步关注(并且可能会为您赢得一些选票)。
-
哦,快,我对这一切都不熟悉。我会相应地更新。
标签: python shapefile matplotlib-basemap contourf