我的问题与this question非常相似!但是我想用1个圆夹住2个或更多的三角形。
所以我尝试用add_patch
添加2个三角形,但是会引发语法错误:
patchpoly = ax.add_patch(polygon1, polygon2)
所以我知道我不能这样走。
代码如下:
fig, ax = plt.subplots()
polygon1 = plt.Polygon([(0,0.6),(1,2),(2,0.4)],color='g',alpha=0.25)
polygon2 = plt.Polygon([(0,0),(1,0.5),(0.5,1)],color='b',alpha=0.25)
circle = plt.Circle((0,0), 1.0, color='r', alpha=0.25)
patchpoly = ax.add_patch(polygon1) # i know this line would be meaningless
patchpoly = ax.add_patch(polygon2)
ax.add_patch(circle)
patchpoly.set_clip_path(circle)
答案 0 :(得分:0)
嗯,你快到了;只需给polygon2
补丁添加一个唯一的名称,即patchpoly2 = ax.add_patch(polygon2)
,然后通过patchpoly2.set_clip_path(circle)