2014-03-24 27 views
1

我想繪製一個三角形,但其中一側需要是一個圓形段。該示例不起作用:需要刪除圈外的所有藍色。這可以直接完成,無需自己計算整個輪廓?在matplotlib中裁剪一個帶圓圈的老鷹

謝謝!

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() 

回答

2

如果捕獲添加的多邊形修補程序,則可以使用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) 

enter image description here

+0

謝謝!大! – frits