在 Python Matplotlib 中的现有绘图中添加一层多边形

Adding a layer of polygons to an existing plot in Python Matplotlib

目前我正在使用 tripcolor 函数对 3D 点数据进行三角测量和着色。我得到的是地图数据的一部分。还有更多我想使用的数据。我还有一个包含一组多边形的 shapefile。我的工作目标是对屋顶类型进行分类。所以 shapefile 中的形状是边界,其中包括您可以看到的地图中的屋顶。我现在拥有的是 x- y- 和 z- 坐标中的一组点,因此我可以渲染您在下面看到的地图。如何在此图中再添加一层,将形状的多边形绘制到地图中?

plt.tripcolor(x, y, z, shading='gouraud')

可以使用 PolyCollection 在图上添加形状。

import matplotlib.pyplot as plt
from matplotlib import collections
import numpy as np; np.random.seed(17)

b = np.random.rand(100,3)

fig, ax = plt.subplots()
ax.tripcolor(b[:,0],b[:,1],b[:,2], shading='gouraud')

polys = [np.random.rand(4,2)*.3+np.random.rand(1,2)*((2*i+1)/6.) for i in range(3)]
pc = collections.PolyCollection(polys, color="crimson")    
ax.add_collection(pc)

plt.show()