Note

Go to the endto download the full example code.

Hatch demo#

Hatches can be added to most polygons in Matplotlib, includingbar,fill_between,contourf, and children ofPolygon.They are currently supported in the PS, PDF, SVG, macosx, and Agg backends. The WXand Cairo backends do not currently support hatching.

See alsoContourf hatching foran example usingcontourf, andHatch style reference for swatchesof the existing hatches.

importmatplotlib.pyplotaspltimportnumpyasnpfrommatplotlib.patchesimportEllipse,Polygonx=np.arange(1,5)y1=np.arange(1,5)y2=np.ones(y1.shape)*4fig=plt.figure()axs=fig.subplot_mosaic([['bar1','patches'],['bar2','patches']])axs['bar1'].bar(x,y1,edgecolor='black',hatch="/")axs['bar1'].bar(x,y2,bottom=y1,edgecolor='black',hatch='//')axs['bar2'].bar(x,y1,edgecolor='black',hatch=['--','+','x','\\'])axs['bar2'].bar(x,y2,bottom=y1,edgecolor='black',hatch=['*','o','O','.'])x=np.arange(0,40,0.2)axs['patches'].fill_between(x,np.sin(x)*4+30,y2=0,hatch='///',zorder=2,fc='c')axs['patches'].add_patch(Ellipse((4,50),10,10,fill=True,hatch='*',facecolor='y'))axs['patches'].add_patch(Polygon([(10,20),(30,50),(50,10)],hatch='\\/...',facecolor='g'))axs['patches'].set_xlim(0,40)axs['patches'].set_ylim(10,60)axs['patches'].set_aspect(1)plt.show()
hatch demo

Gallery generated by Sphinx-Gallery