MATLAB: How to show striped patterns or any other texture for specific bars when using the BAR function along with grouping in MATLAB R2011a (7.12)

barchartsgrouphatchedMATLAB

I am trying to create a grouped bar chart in which I would like to specify particular patterns for bars in a particular group.
For example, I want the 3rd and the 4th bars in group 1 to have dashed pattern, and the 5th and 6th bars in group 2 to have similar dashed patterns.

Best Answer

In order to create a grouped bar chart with specific bars having patterns using the BAR function, plot two bar graphs in the same figure using HOLD ON.
To get patterns on BAR graphs please refer to the following link of MATLAB Central:
Refer to the comments in the code below to use the above link in creating the required resulting bar graph:
%The code simply puts one plot on the other.
data = [3,0,5,0; 0,3,2,9;6,6,0,0]; %This should be your initial matrix. The data points to be hatched should be made 0
overdata = [0,2,0,5; 1,0,0,0;0,0,5,3]; %The points other than the ones that are to be hatched should be made 0.
%In this case in Group 1, the 2nd and 5th bars, Group 2 only the 1st bar
%and in Group 3 the 3rd and 4th bar are selected.
b = bar(data);%plot the graph with the bars for hatched lines missing
hold on
c = bar(overdata,'r');%plot the graph only for the hatched bars. Currently it will show it in Red. But you should obtain this graph from the MATLAB Central file which gives hatched bars.
Related Question