How to print values of a bar plot...
조회 수: 4 (최근 30일)
이전 댓글 표시
I have this code that works fine. The problem with it is that it prints the value of the variable 'lab' which contains text, and i want to print the values of 'd' that contains numbers... i try to fix the code but i couldn't. I would appreciate any help. Thanks!
d=[306 286 273 242 238];
lab={'Switzerland' 'Germany' 'Austria' 'Norway' 'Sweden'};
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]);
yValues = d' + 0.5;
text(xd, yValues(:),lab.','horizontalalignment','center');
댓글 수: 0
답변 (1개)
Star Strider
2014년 9월 4일
Comment-out the line that sets the labels to ‘lab’ and substitute ‘d’:
% set(gca,'xticklabel',lab.');
set(gca,'xticklabel',d.');
댓글 수: 2
Star Strider
2014년 9월 4일
편집: Star Strider
2014년 9월 4일
I didn’t see that, but then I wasn’t aware you wanted those labels to disappear as well.
Comment-out this line to eliminate the top labels:
% text(xd, yValues(:),lab.','horizontalalignment','center');
What do you want along the x-axis?
Do you want the ‘d’ numbers printed at the top instead?
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!