Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
annotate grouped bar graph

Subject: annotate grouped bar graph

From: Wendy

Date: 7 Feb, 2010 19:12:02

Message: 1 of 2

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

Subject: annotate grouped bar graph

From: us

Date: 7 Feb, 2010 19:41:02

Message: 2 of 2

"Wendy " <wlq121@gmail.com> wrote in message <hkn3a2$fps$1@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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us