You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
Basic usage
y = [2 2 3 2 5; 2 5 6 2 5; 9 8 9 2 5];
% Create hatched bar chart object
HB = hatchedBar(y, 'HatchType',{'/','\','.','_','x'}, 'Horizontal','off');
% Draw hatched bar chart
HB = HB.draw();
% Hatch Type
% ==========================================
% "/" — Forward diagonal
% "\" — Backward diagonal
% "_"/"-" — Horizontal
% "|" — Vertical
% "+" — Cross
% "x" — Diagonal Cross
% "." — Dot
% "w"/"W"/"white" — White
% "k"/"K"/"black" — Black
% "gray"/"grey" — Gray
% ==========================================
Display bar labels for stacked horizontal bar chart
figure(4)
y = [2 2 -3 -2 -5; -2 -5 6 2 5; 9 8 9 2 5; -3 -5 6 2 5; 4 8 5 2 5];
% Create stacked horizontal hatched bar chart object
HB4 = hatchedBar(y, 'HatchType',{'/','\','.','x','|'}, 'stacked', 'Horizontal','on');
HB4 = HB4.draw();
barHdl = findobj(gca, 'Tag','barBox', 'Type','Bar');
for i = 1:length(barHdl)
xtips = barHdl(i).XEndPoints;
ytips = barHdl(i).YEndPoints;
labels = string(barHdl(i).YData);
text(ytips, xtips + .42, labels, 'HorizontalAlignment','center',...
'VerticalAlignment','baseline', 'FontName','Times New Roman')
end
Face color
figure(2)
y = [2 2 -3 -2 5; -2 -5 6 5 3; 9 8 9 2 1; -3 -5 6 2 2];
HB2 = shadowHist(y, 'ShadowType',{'/','\','.','x','|'}, 'stacked', 'Horizontal','on');
HB2 = HB2.draw();
HB2 = HB2.legend({'AAAAAAA','BBBBBBB','CCCCCCC','DDDDDDD','EEEEEEE'}, 'FontName','Cambria', 'FontSize',11);
% Change face color
% Palette: user-defined nx3 matrix (values in [0,1])
colorList = [ 52 101 117
121 172 189
155 177 187
236 189 149
228 222 206]./255;
barHdl = findobj(gca, 'Type','Bar', 'Tag','barBox');
lgdHdl = findobj(gca, 'Type','Patch', 'Tag','barBox');
for i = 1:length(barHdl)
set(barHdl(length(barHdl) + 1 - i), 'FaceColor',colorList(i,:))
set(lgdHdl(length(barHdl) + 1 - i), 'FaceColor',colorList(i,:))
end
Cite As
Zhaoxu Liu / slandarer (2026). hatched bar chart (阴影/条纹填充柱状图) (https://uk.mathworks.com/matlabcentral/fileexchange/117005-hatched-bar-chart), MATLAB Central File Exchange. Retrieved .
General Information
- Version 2.0.2 (526 KB)
MATLAB Release Compatibility
- Compatible with R2017b and later releases
Platform Compatibility
- Windows
- macOS
- Linux
| Version | Published | Release Notes | Action |
|---|---|---|---|
| 2.0.2 | Fixed bug where horizontal hatched legend did not display |
||
| 2.0.1 | debug of 2.0.0 |
||
| 2.0 | + More detailed examples |
||
| 1.6.1 | Modify garbled characters |
||
| 1.6.0 | colorful |
||
| 1.5.1 | debug of 1.5.0 |
||
| 1.5.0 | use 'Horizontal','on' to draw Horizontal Histogram |
||
| 1.0.0 |
