【问题标题】:clipping a triagle with a circle in matplotlib在 matplotlib 中用圆圈剪裁三角形
【发布时间】:2014-03-24 22:44:44
【问题描述】:

我想画一个三角形,但其中一个边必须是圆段。该示例不起作用:需要删除圆圈外的所有蓝色。这可以直接完成,而无需自己计算整个轮廓吗?

谢谢!

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
polygon = plt.Polygon([(0,0.6),(1,2),(2,0.4)], True)
circle=plt.Circle((0,0),1.0,facecolor='None', edgecolor='black')
ax.add_patch(polygon)
ax.add_patch(circle)

plt.show()

【问题讨论】:

    标签: matplotlib


    【解决方案1】:

    如果您捕获多边形的添加补丁,您可以使用set_clip_path 属性。鉴于你的例子:

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    
    polygon = plt.Polygon([(0,0.6),(1,2),(2,0.4)], True)
    circle = plt.Circle((0,0),1.0,facecolor='None', edgecolor='black')
    
    patch_poly = ax.add_patch(polygon)    
    ax.add_patch(circle)
    
    patch_poly.set_clip_path(circle)
    

    【讨论】:

      猜你喜欢
      • 2016-02-11
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多