Note

Go to the endto download the full example code.

Hatch style reference#

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 demo for more usage examples.

importmatplotlib.pyplotaspltfrommatplotlib.patchesimportRectanglefig,axs=plt.subplots(2,5,layout='constrained',figsize=(6.4,3.2))hatches=['/','\\','|','-','+','x','o','O','.','*']defhatches_plot(ax,h):ax.add_patch(Rectangle((0,0),2,2,fill=False,hatch=h))ax.text(1,-0.5,f"'{h} '",size=15,ha="center")ax.axis('equal')ax.axis('off')forax,hinzip(axs.flat,hatches):hatches_plot(ax,h)
hatch style reference

Hatching patterns can be repeated to increase the density.

fig,axs=plt.subplots(2,5,layout='constrained',figsize=(6.4,3.2))hatches=['//','\\\\','||','--','++','xx','oo','OO','..','**']forax,hinzip(axs.flat,hatches):hatches_plot(ax,h)
hatch style reference

Hatching patterns can be combined to create additional patterns.

fig,axs=plt.subplots(2,5,layout='constrained',figsize=(6.4,3.2))hatches=['/o','\\|','|*','-\\','+o','x*','o-','O|','O.','*-']forax,hinzip(axs.flat,hatches):hatches_plot(ax,h)
hatch style reference

References

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

Tags:purpose: reference

Total running time of the script: (0 minutes 1.841 seconds)

Gallery generated by Sphinx-Gallery