From: John on
how to show the value of each bar of a histogram?

thanks!
From: us on
"John " <wwwinfor(a)gmail.com> wrote in message <hn0coh$otf$1(a)fred.mathworks.com>...
> how to show the value of each bar of a histogram?
>
> thanks!

one of the (tedious) solutions

% the data
d=[
4 8 9 7 4
8 7 5 5 8
2 7 1 4 9
];
lab={
'ab' 'bc' 'ef' 'ww' 'qq'
'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
From: John on
Thank you very much for your quick reply!

however, following your code the output is a bar chart showing the "variable name" of each bar rather than the numerical value of each colored bar.

My question is "how to show, on top of each bar, the numerical value as represented by each of the bars in a histogram?".

Just like in Excel, for each bar chart created, we can choose to show on the chart the numerical value on top of each bar.

BTW, it seems you didn't use the function "hist" at all in your code. I'm a bit confused ...... Can the "hist" function be done by using other function or functions?

Thanks again and wait for your reply!
From: us on
"John " <wwwinfor(a)gmail.com> wrote in message <hn0ein$hpg$1(a)fred.mathworks.com>...
> Thank you very much for your quick reply!
>
> however, following your code the output is a bar chart showing the "variable name" of each bar rather than the numerical value of each colored bar.

well... think, and simply replace LAB with whatever content you want as long as it is a CELL array, eg,

% d=...
lab=num2cell(d);
% rest of code

> BTW, it seems you didn't use the function "hist" at all in your code. I'm a bit confused ...... Can the "hist" function be done by using other function or functions?

note: the question was not about HIST, it was about BAR...
in the exemplary snippet, D simulates the result of a virtual HIST...

> Thanks again and wait for your reply!

ok...

us