text to stack bar

조회 수: 2 (최근 30일)
Prasad Joshi
Prasad Joshi 2022년 4월 13일
댓글: Mathieu NOE 2022년 4월 13일
Hello ,
I am thinking of adding text to stack bar but its not working can someone suggest improvement in code . where i am going wrong. Thanks in advance like each value should be in that mark only eg :- 1051 in red , 1427 in blue mark & 1580 in red mark
clear all
close all
clc
x=input('Enter the first column:','s')
r=xlsread('Master_data.xlsx',strcat(x,':E',num2str((str2num(x(2:strlength(x)))+8))))
i=1
C(1,:)=[r(i+1) r(i+10) r(i+19) r(i+28) r(i+2) r(i+11) r(i+20) r(i+29)]
C(2,:)=[r(i+4) r(i+13) r(i+22) r(i+31) r(i+5) r(i+14) r(i+23) r(i+32)]
C(3,:)=[r(i+7) r(i+16) r(i+25) r(i+34) r(i+8) r(i+17) r(i+26) r(i+35)]
D(1,:)=C(1,:)
D(2,:)=C(2,:) -(C(1,:))
D(3,:)=C(3,:)-(C(2,:))
D=D'
h=figure
hB=bar(D,'stacked')
set(hB(1),'Facecolor','red')
set(hB(2),'Facecolor','blue')
set(hB(3),'Facecolor','green')
legend('10 sec','25 sec', '60 sec')
xt = get(gca, 'XTick');
set(gca, 'XTick', xt, 'XTickLabel', {'C1-Case1' 'C1-Case2' 'C1-Case3' 'C1-Case4' 'C2-Case1' 'C2-Case2' 'C2-Case3' 'C2-Case4'},'fontsize',12)
title('Cumulative CO emission[mg] ','fontsize',12);
ylabel('Cumulative CO emission[mg]','FontSize',12)
labels_stacked=num2str(C(:,1),'%.1f ');
hText = text(1:size(C), C(:,1), labels_stacked);
set(hText, 'VerticalAlignment','top', 'HorizontalAlignment', 'center','FontSize',12, 'Color','k');
  댓글 수: 2
Riccardo Scorretti
Riccardo Scorretti 2022년 4월 13일
Mathieu NOE
Mathieu NOE 2022년 4월 13일
hi
the y coordinates of the text ( = C(:,1) in your code) is not correct if you want the text to appear below the top of each color zone (or in the middle)
all the best

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by