% plot bar graph with patterns
% b1: output of original "bar" matlab function
% varargin <= input of original "bar" matlab function
% patterns: {'\','/','*','-','|','+', ' ', 's'} (solid filled)
% lcolor: line color {[R G B]} between 0-1
% lspacing: {1}: space between lines
% lwidth: {1}: line width of patterns
% * if the size of input not match with the data, using the first unit for all bars
% %Example 1:
% figure(1);clf;set(gcf,'color','w');
% dataBar=rand(3,5)-0.5;
% patterns={'\*+ s','\*+ s','\*+ s'};
% lcolor={lines(5),lines(5),lines(5)};
% lspacing={[1 1 1 1 1],[1 1 1 1 1],[1 1 1 1 1]};lwidth={[1 1 1 1 1],[1 1 1 1 1],[1 1 1 1 1]};
% b1=bar_pattern(patterns,lcolor,lspacing,lwidth,dataBar,'FaceColor',[1 1 1],'BarWidth',1);
% b1(5).FaceAlpha = 0.5;
%
% %Example 2:
% figure(2);set(gcf,'color','w')
% dataBar=rand(1,5)-0.5;
% patterns={'/-\ s'};lcolor={jet(5)};lspacing={[1 1 1 1 1]};lwidth={[1 1 1 1 1]};
% b1=bar_pattern(patterns,lcolor,lspacing,lwidth,dataBar,'FaceColor',[1 1 1]);
%
% %Example 3: Apply with bar
% figure(3);set(gcf,'color','w');
% dataBar=rand(3,5)-0.5;
% patterns={'/+\ x','/+\ x','/+\ s'};
% lcolor={lines(5),lines(5),lines(5)};
% lspacing={[1 1 1 1 1],[1 1 1 1 1],[1 1 1 1 1]};lwidth={[2 2 2 2 2],[2 2 2 2 2],[2 2 2 2 2]};
% b1=bar_pattern(patterns,lcolor,lspacing,lwidth,dataBar,'FaceColor',[1 1 1],'BarWidth',1,'LineWidth',2);
% b1=bar(dataBar,'FaceAlpha',0.2,'BarWidth',1,'LineWidth',2,'FaceColor','flat');hold on;
% set(gca,'FontWeight','bold','LineWidth',2,'FontSize',20,'xticklabel',{'A','B','C'})
引用格式
Chaohsiung Hsu (2025). Plot bar graph with patterns (https://www.mathworks.com/matlabcentral/fileexchange/126849-plot-bar-graph-with-patterns), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2023a
与 R2021b 及更高版本兼容
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0 |