在matplotlib中用圆剪裁一个triagle [英] clipping a triagle with a circle in matplotlib
本文介绍了在matplotlib中用圆剪裁一个triagle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想画一个三角形,但是侧面之一必须是一个圆弧段.该示例不起作用:需要清除圆圈外的所有蓝色.可以直接完成而无需自己计算整个轮廓吗?
I would like to draw a triangle, but one of the sides needs to be a circle segment. The example is not working: all blue outside the circle needs to be removed. Can this be done directly, without calculating the entire contour myself?
谢谢!
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()
推荐答案
如果您捕获多边形的添加补丁,您可以使用 set_clip_path
属性.给出您的示例:
You can use the set_clip_path
property if you capture the added patch of the polygon. Given your example:
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)
这篇关于在matplotlib中用圆剪裁一个triagle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文