2

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?

Thank you!

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()
frits
  • 327
  • 2
  • 15

1 Answers1

3

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)

enter image description here

Rutger Kassies
  • 61,630
  • 17
  • 112
  • 97