Fills an area with hatching or speckling.
Updated 19 Dec 2012

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

In MATLAB, there are many functions that create regions filled with solid colors (e.g. contourf, area, bar). To do this, a function creates "patch objects" and assigns a single color to each one. Instead of a solid fill, one often wants to fill a patch with a hatch or speckle pattern instead. MATLAB has no built-in way to do this.

The hatchfill function fills patch objects with hatching or speckling. In most cases, adding hatching to a 2D plot requires only three lines of code. For example:

[c,h] = contourf(x,y,z,[0 0]);
hp = findobj(h,'type','patch');

This fills the zero contour with hatching. Hatchfill takes additional parameters if custom patterns are desired. This package incorporates code from Rich Pawlowicz, Iram Weinstein, and Kirill Pankratov.

Cite As

Neil Tandon (2024). Hatchfill (https://www.mathworks.com/matlabcentral/fileexchange/30733-hatchfill), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Surfaces, Volumes, and Polygons in Help Center and MATLAB Answers

Inspired by: hatch.m

Inspired: kristinbranson/JAABA, stipple, Hatchfill2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Added additional check for axes that are only one level up. (Suggested by Dan K.)

Consolidated code into single file.

Simplified code.

Updated description.

Fixed bug reported by Dmytro Lituiev.

Updated description

Minor bug fix.

Now is compatible with logarithmic axes.

Polished the examples/documentation a little.

A little housecleaning...