圆,楔和多边形
此示例演示如何使用修补程序集合。
import numpy as npfrom matplotlib.patches import Circle, Wedge, Polygonfrom matplotlib.collections import PatchCollectionimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)fig, ax = plt.subplots()resolution = 50 # the number of verticesN = 3x = np.random.rand(N)y = np.random.rand(N)radii = 0.1*np.random.rand(N)patches = []for x1, y1, r in zip(x, y, radii):circle = Circle((x1, y1), r)patches.append(circle)x = np.random.rand(N)y = np.random.rand(N)radii = 0.1*np.random.rand(N)theta1 = 360.0*np.random.rand(N)theta2 = 360.0*np.random.rand(N)for x1, y1, r, t1, t2 in zip(x, y, radii, theta1, theta2):wedge = Wedge((x1, y1), r, t1, t2)patches.append(wedge)# Some limiting conditions on Wedgepatches += [Wedge((.3, .7), .1, 0, 360), # Full circleWedge((.7, .8), .2, 0, 360, width=0.05), # Full ringWedge((.8, .3), .2, 0, 45), # Full sectorWedge((.8, .3), .2, 45, 90, width=0.10), # Ring sector]for i in range(N):polygon = Polygon(np.random.rand(N, 2), True)patches.append(polygon)colors = 100*np.random.rand(len(patches))p = PatchCollection(patches, alpha=0.4)p.set_array(np.array(colors))ax.add_collection(p)fig.colorbar(p, ax=ax)plt.show()

参考
此示例中显示了以下函数,方法,类和模块的使用:
import matplotlibmatplotlib.patchesmatplotlib.patches.Circlematplotlib.patches.Wedgematplotlib.patches.Polygonmatplotlib.collections.PatchCollectionmatplotlib.collections.Collection.set_arraymatplotlib.axes.Axes.add_collectionmatplotlib.figure.Figure.colorbar
