From: Wendy on
Hi,

I plot a grouped bar graph, and I want to annotate every single bar in each group. Does anybody know how to do this. I think it has to use barseries somehow. My example is following:

% data
test = [4 8 9 7 4;
8 7 5 5 8;
2 7 1 4 9];
bar(test);
% annotation
L = {'a' 'b' 'e' 'w' 'q';
'q' 'd' 'c' 'w' 'r';
'w' 'i' 'yr' 'w' 'r'};

Thank you very much.
Wendy
From: us on
"Wendy " <wlq121(a)gmail.com> wrote in message <hkn3a2$fps$1(a)fred.mathworks.com>...
> Hi,
>
> I plot a grouped bar graph, and I want to annotate every single bar in each group. Does anybody know how to do this. I think it has to use barseries somehow. My example is following:
>
> % data
> test = [4 8 9 7 4;
> 8 7 5 5 8;
> 2 7 1 4 9];
> bar(test);
> % annotation
> L = {'a' 'b' 'e' 'w' 'q';
> 'q' 'd' 'c' 'w' 'r';
> 'w' 'i' 'yr' 'w' 'r'};
>
> Thank you very much.
> Wendy

one of the (tedious) solutions

% the data
d=[
4 8 9 7 4
8 7 5 5 8
2 7 1 4 9
];
lab={
'a' 'b' 'e' 'w' 'q'
'q' 'd' 'c' 'w' 'r'
'w' 'i' 'yr' 'w' 'r'
};
% the engine
bh=bar(d);
xd=get(bh,'children');
xd=get([xd{:}],'xdata');
xd=cat(2,xd{:});
xdd=diff(xd);
xd=sort(xd(1,:)+.5*xdd(2,1));
set(gca,'xtick',xd);
set(gca,'xticklabel',lab.');
yl=get(gca,'ylim');
set(gca,'ylim',[yl(1),yl(2)+3]);
text(xd,repmat(11,1,numel(xd)),lab.','horizontalalignment','center');

us