File Exchange

image thumbnail

Hatched Fill Patterns

version (2.71 KB) by Ben Hinkle
Replace solid colors with patterns.


Updated 08 Jan 2019

View Version History

View License

Will create a bitmap copy of a figure with distinct colors replaced with hatch patterns. This is useful for b+w bitmap output. Vector output is not supported.

Cite As

Ben Hinkle (2021). Hatched Fill Patterns (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (44)

atf atfta

thank you so much

Ajinkya Bankar

I want to increase the width of hatched lines and increase the spacing between hatched lines. Please help me. Thank you.

xiaohui qi

well working for bar in Matlab 2017a

wei zhou

working for bar in Matlab 2019

Dianlei Xu

the colorlist doesn't work for bar. but it works well for pie

Dennis Frank

It doesn't ALWAYS work well for clustered (group) bars

Hosain Kolour

doesn't work


does not work..............


Yantong Wang

If "hardcopy" function is not worked in your Matlab version, comment "bits = hardcopy(h,'-dzbuffer','-r0');"
then add "bits = print('-RGBImage');" in applyhatch file.


Unfortunately it does not work (anymore). Making the suggested change did not work for me.

The undocumented 'hardcopy' function has been removed; use the documented 'print' command with the '-RGBImage'
option instead. See the 'print' command documentation for details.

Error in applyhatch (line 38)
bits = hardcopy(h,'-dzbuffer','-r0');

Zack Leasor


In Matlab 2016a, I've found that pattern is not controlled properly. For example, some patterns are duplicated and also their order is not what I want. I solved the duplicated pattern problem indirectly by like bellows.
If you want to adjust the pattern to 6 bar such as " applyhatch(gcf,'.-+/|x');", try to type this "applyhatch(gcf,'.-++/||xx');" instedly.
So you can avoid the duplicated pattern at least, even order problem is still not solved.
Anyway, even these bugs, this function is so great!. Appreciate this!

george Foncham

Ananya Malik


Will it only work for the bar plot? I tried with area but couldn't find what I was looking for?

Can you please share an example of functional usage?

Appreciate your help!


I am getting error while trying to use this function.
Lets say,
D=[26.834 16.74 12.37
20.238 18.84 14.201
21.523 15.14 12.25
22.839 14.64 13.57
22.8585 16.34 13.09775];
Please help me know how I can use applyhatch or makehatch to get a barplot in grayscale having hatched patterns.
Thank you,



Hi, I used this function and changed the colors of my bar plot to patterns, however, the background of the figure is always gray when copied. Where to change that?



This work is good, but not good enough, for bitmap will cause other trouble. I wish MATLAB will provide an offical version to overcome this shortage.


Can this work with 'area' plots?

Jonathan C. Lansey

Great worked right out of the "box" thanks!


This is really a good thing!

Qing Xie

Qing Xie


Excellent, this is exactly what am I looking for.


Thanks a lot.


Thanks so much! This is so useful for black and white printing. One tip to users is to change the gcf color (color background) to white before applying the hatch. it seems once the hatch is applied the figure isn't able to be modified further.

Oleg Komarov

I agree with Brian: this should be a built in feature in matlab. I always have to export data and do my graphs in excel.
Also, i think the "pointed" texture should be improved to match the logic it has in excel, that is it shouldn't simply make bigger points.


textures don't line up - but colour mapping is a good idea - Aha, i've found the problem, when the image is put into the figure, it is made _slightly_ bigger, giving the appearence (and output to file) of a bitmap with an extra line in its textures in the middle: lines 100 and 101 should read
set(newfig,'position',[fpos(1:2) figsize(3) figsize(4)]);
set(imaxes,'position',[0 0 figsize(3) figsize(4)],'visible','off');
i.e. remove the plus one

Elena D

Tobias Conradsson

This saved me a lot of work and time, thanks

vignesh ravi

Jihun Jung

thanks alot! very useful one.

Andreas E.

Works great!


Thanks, I started writing a code for it. After that, I found this program. I will be so helpful.

Trond Kristiansen

Very useful! Graze!

Guillermo Franco

Fantastic! Thanks!

Mark Lilly

Needed to make black and white images for a paper and this utility saved the day. Highly reccommend!!! Thanks so much.

Christopher Brown

Excellent. Can be easily modified to use custom fill patterns too.

Mike Zierolf

Thanks a lot! This worked exactly as advertised.

Danny Zhai

That is what I have been looking for! Nice job!

Brian Katz

This should be included as a default feature in MatLab. A much needed function for producing any publications graphics.

Denis Gilbert

The two m-files (APPLYHATCH and MAKEHATCH) address a long-standing shortcoming in the basic 2-D plotting capabilities of Matlab. Works well with PIE, BAR and CONTOURF.

Good job Ben !

MATLAB Release Compatibility
Created with R11.1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!