【问题标题】:clip 2 or more triangles with a circle using matplotlib使用 matplotlib 用圆形剪辑 2 个或更多三角形
【发布时间】:2019-10-05 20:57:31
【问题描述】:

我的问题与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)

结果: https://imgur.com/a/jnVXUuE

【问题讨论】:

    标签: matplotlib clipping


    【解决方案1】:

    嗯,你快到了;只需给polygon2 补丁一个唯一的名称,即patchpoly2 = ax.add_patch(polygon2),然后还通过patchpoly2.set_clip_path(circle) 指示补丁在圆圈的末尾被“剪辑”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 2021-11-20
      • 2014-06-21
      • 2018-08-22
      • 1970-01-01
      • 2015-08-12
      • 2021-12-06
      相关资源
      最近更新 更多