-1

my question is very similar to this question! but i want to use 1 circle to clip 2 triangles or more.

so i tried adding 2 triangles with add_patch but it throws syntax error:

patchpoly = ax.add_patch(polygon1, polygon2)

so i know i can't go this way.

here is the code:

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)

and the result: https://i.stack.imgur.com/URQEt.jpg

AcaNg
  • 704
  • 1
  • 9
  • 26

1 Answers1

0

Well you're nearly there; just give the polygon2 patch a unique name, i.e. patchpoly2 = ax.add_patch(polygon2) and then also instruct the patch to get 'clipped' at the end of the circle via patchpoly2.set_clip_path(circle)

Asmus
  • 5,117
  • 1
  • 16
  • 21