资讯动态

Python绘制圆形、扇形和多边形图

发布时间:2026/8/6 9:50:49 来源:尧图企业网站定制
此示例演示了如何使用collections.PatchCollection。另请参阅 Matplotlib 艺术家的参考资料它会将每个艺术家分别添加到其自己的坐标轴中。import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.collections import PatchCollectionfrom matplotlib.patches import Circle, Polygon, Wedge# 固定随机状态以实现可重复性np.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)#关于楔形的一些限制条件patches [Wedge((.3, .7), .1, 0, 360), # Full circleWedge((.7, .8), .2, 0, 360, width0.05), # Full ringWedge((.8, .3), .2, 0, 45), # Full sectorWedge((.8, .3), .2, 45, 90, width0.10), # Ring sector]for i in range(N):polygon Polygon(np.random.rand(N, 2), closedTrue)patches.append(polygon)colors 100 * np.random.rand(len(patches))p PatchCollection(patches, alpha0.4)p.set_array(colors)ax.add_collection(p)fig.colorbar(p, axax)plt.show()参考文献https://matplotlib.org/stable/gallery/shapes_and_collections/patch_collection.html

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价