Note
Go to the endto download the full example code.
Mmh Donuts!!!#
Draw donuts (miam!) usingPaths andPathPatches.This example shows the effect of the path's orientations in a compound path.
importmatplotlib.pyplotaspltimportnumpyasnpimportmatplotlib.patchesasmpatchesimportmatplotlib.pathasmpathdefwise(v):return{+1:"CCW",-1:"CW"}[v]defmake_circle(r):t=np.arange(0,np.pi*2.0,0.01)x=r*np.cos(t)y=r*np.sin(t)returnnp.column_stack((x,y))fig,ax=plt.subplots()inside_vertices=make_circle(0.5)outside_vertices=make_circle(1.0)codes=np.full(len(inside_vertices),mpath.Path.LINETO)codes[0]=mpath.Path.MOVETOfori,(inside,outside)inenumerate(((1,1),(1,-1),(-1,1),(-1,-1))):# Concatenate the inside and outside subpaths together, changing their# order as neededvertices=np.concatenate((outside_vertices[::outside],inside_vertices[::inside]))# Shift the pathvertices+=(i*2.5,0)# The codes will be all "LINETO" commands, except for "MOVETO"s at the# beginning of each subpathall_codes=np.concatenate((codes,codes))# Create the Path objectpath=mpath.Path(vertices,all_codes)# And plot itpatch=mpatches.PathPatch(path,facecolor='#885500',edgecolor='black')ax.add_patch(patch)ax.annotate(f"Outside{wise(outside)},\nInside{wise(inside)}",(i*2.5,-1.5),va="top",ha="center")ax.set(xlim=(-2,10),ylim=(-3,2),aspect=1,title="Mmm, donuts!")plt.show()

References
The use of the following functions, methods, classes and modules is shownin this example: