Fills an area with hatching or speckling (Updating original hatchfill by Neil Tandon)
Updated 11 Jan 2018

View License

This submission updates the popular submission (#30733) by Neil Tandon to place hatching pattern on patch objects. The main algorithm to form hatching pattern remains mostly the same as the original while more formatting options are exposed to the user and hatchfill2 brings the support for HG2 graphics system (since R2014b).
* Supported base graphics objects: PATCH, HGGROUP, AREA, BAR, and CONTOUR objects are additionally supported. Pre-HG2 (pre-R2014b) MATLAB releases are no longer supported.
* Supports 3D surfaces. Note: Hatching would not come out correctly on a curved surface.
* Four types of hatching patterns:
- 'single' single lines
- 'cross' double-crossed hatch
- 'speckle' speckling inside the patch boundary (partial support)
- 'outspeckle' speckling outside the boundary (partial support)
* User-definable options are now set via parameter name/value pair input argument interface. Options include HatchAngle, HatchDensity, HatchOffset, HatchColor, HatchLineStyle, HatchLineWidth, SpeckleMarkerStyle, and SpeckleFillColor
* Active formatting - the hatch line object listens to the changes in the patch object or axes to keep the hatching true to user options all the time (sans print support at this time)
* Basic graphics object properties (Visible, Clipping, HitTest, Interruptible, BusyAction, and UIContextMenu) of the hatch line object are synchronized to the base patch object. Only Visible property can be de-linked by setting HatchVisible option to either 'on' or 'off'.

* Speckling multi-face PATCH and HG2 CONTOUR is not implemented correctly. If anyone needs this feature fixed, post a request and I'll see what I can do.

* Print support - implementing "printmode" similar to lateximage
* Multi-face speckle support - eliminating all the interior edges in gethgdata
* Legend support - HG2 is making this really challenging if not impossible. Users suggest using legendflex (FEX#31092 or at https://github.com/kakearney/legendflex-pkg). See the comments below by Drecalde & SeungHyoung Ryu for how-to. Thanks guys!!

Cite As

Kesh Ikuma (2024). Hatchfill2 (https://www.mathworks.com/matlabcentral/fileexchange/53593-hatchfill2), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Hatchfill, lateximage

Inspired: stipple

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

Rev. 7
* Added support for 3D faces
* Removed HatchSpacing option
* Added HatchDensity option

Rev. 6 (release 7)
* Fixed contours object hatching behavior, introduced in rev.5
* Added ContourStyle option to enable fast drawing if contour is convex

Improved support for converting contours objects to hatch

Uploaded correct files *facepalm*
* Removed UseHG2 nagging warning
* Worked around the issue with HG2 contour object with Fill='off'

* Added support for HG2 AREA object
* Bug fixes

v2.0 (r3)
* Enabled active formatting
* Enabled basic property syncing

Editing Description
* Fixed a couple major bugs for hatching HG2 surface object