File Exchange

image thumbnail


version (5.86 KB) by Brian Katz
Modification of APPLYHATCH_PLUS, allowing for color and variable thickness for hatch patterns.


Updated 26 Nov 2020

View Version History

View License

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

This is a modification of previously submitted APPLYHATCH_PLUS.
APPLYHATCH_PLUSC creates a bitmap version of the defined figure where colored elements are replaced with specified colored hatch patterns.
APPLYHATCH_PLUSC allows for the definition of colors for the hatch patterns. Color may be defined using char string or RGB values. Various examples are provided showing some possibilities of APPLYHATCH_PLUSC and MAKEHATCH_PLUS.
Note: This function is different from Brandon Levey's APPLYHATCH_PLUSCOLOR, which has slightly different functionality and syntax.

Cite As

Brian Katz (2021). applyhatch_plusC (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (40)

Qingyuan Wang

Brian Katz

Sorry, maybe it is browser issues for you. It works for me, 2 M files plus the licence file.


When I try to download the function, I get an empty zip file?

Brian Katz

Please verify that if you zoom in the lines are not there. I have just retested (Win10, ' (R2020b) Update 1') and if I zoom in the lines are there. It is a problem with how MatLab subsamples the image on screen. Export the figure and see what it looks like in external applications.
Regarding blurry text, as noted in previous comments, you may need to adjust the resolution (DPI). For example, try >> im_hatchC = applyhatch_plusC(1,'\-x.\x','rkgrgb',[],300,2);


I am having problems. For example, when I try running Example 1 I'm not getting black lines around all of the bars and the tick labels are very poor resolution (I'm running 2020B).

David Burdige

Brian Katz

Attn: I think I have resolved the issues for current MatLab figure functionality (tested with R2020b).
Let me know if there are still difficulties.




@Brian Katz Hello, dear Mr. Brian Katz, have you updated the tool now? I am very eager to use your tool smoothly in the latest Matlab version. Thank you.

Brian Katz

Attn: Please note that I am currently having difficulties getting this to work under the lastest MatLab versions. Some hidden inherent functions that were used are no longer available and the replacement functions do not have the same quality. So, just to let you know I am working on it...

Brian Katz

Hi @Min-He. In your example, this is not possible, because 1 & 6 are the same color from bar. It is the original color that is used to identify elements (see description "colored elements are replaced with specified colored hatch patterns"). They cannot be assigned different hatch info if they are the same color in the original plot. You would need to generate the base plot differently with different colors for the different elements you want to define.

Min He

Hi, @Brain Katz,I am sorry to disturb you.I have a question in using this function and I don't know how to solve it.I want to use bar with style stacked,and the same stack use same hatch and different color.For example:
num = [1 2 3 4 5;6 7 8 9 10];
x = [2,8];
I want the first stack [1 2 3 4 5] use the same hatch and different color,[6 7 8 9 10] use the same hatch and different color.But when I use applyhatch_plusC,I found 1 and 6 have same hatch.Could you help me solve this problem?Thanks a lot!


@Brian, please update when you can. I would love to use this! There doesn't seem to be any other tools of this type available. Thank you for your great work!

Brian Katz

As noted by @liruixinch, you may need to adjust the DPI to get the results you want. MatLab changed the way BMP images are created and I don't like them as much. As such moving the DPI to 300 or 600 provides cleaner text, but you may need to adjust the patterns to be visible. I will think about a way to define different resolutions (for text and hatch), but I do not have time for that soon.
Please test export to TIFF file, in case the poor quality is MatLab image rendering too...

Mei Li

Hi, @Brian Katz,I am a graduate student. I can run the examples in the document using Matlab 2017b, but the figure is not complete. I mean it lost some feature or displayed not matching the code. Moreover, the letters and numbers are very fuzzy. Could you help me solve this problem? Thanks a lot

Brian Katz

@Shuppar, you do not seem to be floolowing the functions syntax, and I do no know what you are trying to do as it is incorrect. Please try the examples and correct this, starting with the simpler cases. PATTERN and PATTERNCOLORS must be the same length.


applyhatch_pluscolor(fh, 'x+/.\-|.', 1, [1 1 1 1 1 0 1 1], CT);

Error using makehatch_plus
Too many input arguments.

Error in applyhatch_pluscolor (line 195)
pattern = makehatch_plus(patterns(pati),6*hatchsc,lw);

Why am I getting the above errors?

liruixinch liruixinch

Thank, this version of code can run in MATLAB2018. And we can adjust the 5th inputing parameter to make the number more smooth.

Brian Katz

Note: This fucntion is currently having issues with the latest version of MatLab (starting from 2017b). I am currently trying to resolve the issue... The error is not regular, but results in non-unique colors/patterns being attributed. Please check your output if you continue to use for now.

Brian Katz

Danny, did you try to improve the resolution of the BMP export for printing? This comment was previously raised and the solution is well documented in the function.


Hello, I am a graduate student using MATLAB 2018a. This code works very well for my bar, but the results are not pretty. The graph I got from this code looks like the low quality figure that I've seen in papers published in the 80s-90s. Especially the letters are not smooth.

Brian Katz

This is something this funtion should do easily. So, sorry, but I don't understand your question. Have you tried to use the function? What is the difficulty?

Tiago Dias

Hello, this work if i have a normal plot, and in a well defined section (x1,y1) -> (x2,y2) instead of filling a blue solid, i woul like to fill with blue diagonal lines?

Ye Xie

Luis Marval

Brian Katz

I don't really understand this comment. If you mean that the resolution of the numbers (tick labels, etc.) is poor, this is due to the fact that this function creates a BMP image. If the resolution is not to your liking, you simply need to increase the DPI. This is what I do for published works, as opposed to screen resolution (the default). Inceasing the DPI will also affect the pattern density, so some playing may be necessary to get exactly what you want.

junmin wang

Thank you. But the number is ugly.

Brian Katz

I have made some very small revisions and the function now works again.
I have tested all examples and there are no more problems as reported.

Andreas Wachaja

seems to be outdated, even the example results in a bad quality plot with Matlab R2015a

When using "aplyhatch_plusC" function, I found the following error.
PATTERN and PATTERNCOLORS must be the same length.
Would you please guide how to fix this error.

Thanks in advance.


I used both applyhatch_plus and makehatch_plus as directed in example given inside the applyhatch_plus. However, in both case I am getting an error stating as below:
im_hatch = applyhatch_plus(gcf,'\-x.',600);
Error message:
"Attempted to access colorlist(1,2); index out
of bounds because numel(colorlist)=1.

Error in applyhatch_plus>nextnonbw (line 142)
colors = (colorlist(out,1) == bits(:,:,1))
& ...

Error in applyhatch_plus (line 69)
[colors,colori] =

I am sure as people had used it multiple time, it is working.
But I am not sure what wrong I did.

Thank you for your help.

Brian Katz

This correction has now been included in the recent update.

Brett Walker

When you test the length, now on line 95, you use the length function which returns the number of elements in the longest dimension (eg. A = [2x3] then length(A) = 3) This will cause a patterncolor matrix with <3 colors (rows) to fail because length(patterns) <3 and length(patterncolor) = 3.

If you use size(patterncolors,1) instead of length(patterncolors) (in the condition on line 95) this problem will be removed as it only returns the number of elements in the first dimension.

Brian Katz

I am sorry but I don't understand the proposed modification. It is necessary to have an equal number of entries in PATTERNS and PATTERNCOLORS, otherwise there would be too few/many combinations. The PATTERNCOLORS can be either a string array of color chars, or a 3 column RGB value. This cannot be more or less than 3 to be RGB.
If you have a specific example where there is a problem, please send it to me.

Tymofii Tereshchenko

Brett Walker

I had to make an alteration to line 97 of applyhatch_plusC to handle a matrix with less than 3 rows for patterncolors.

96: [patterncolors_row patterncolors_col] = size(patterncolors);
97: if length(patterns) ~= patterncolors_row
98: error(...)
99: end

Do you think you could make this, or another appropriate alteration, to allow matrices with less than 3 rows.

Brian Katz

applyhatch_plusC applies to the entire figure, subplots included, so I don't understand the question. You cannot, however, use different hatching rules for two subplots. But, if you assure that the original subplots do not have any colors in common, you should still be free to make the results be anything you want.

Ricardo Roldán

Hey there,
anyway to use it with subplots?

Jea sik SHIN



Nice tool!

Helped me a lot!


MATLAB Release Compatibility
Created with R2017a
Compatible with R2017a to R2020b
Platform Compatibility
Windows macOS Linux

Inspired by: Hatched Fill Patterns Plus

Inspired: stipple

Community Treasure Hunt

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

Start Hunting!