Labels on the top of bars for a bar plot
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi everyone,
I would like to do a bar plot where each bar has a different label, but labels must be different than values contained in "y" vector, because I want to show on the top of each bar the percentage difference than the bar called "25% C_ax".
The values that I would like to show are shown in vector "z" (commented).
I tried to use the code below, but it did not work.
Does anyone could help me?
Thank you very much
clear all
close all
clc
x = categorical({'Rotor only','200% C_{ax}','100% C_{ax}','50% C_{ax}','25% C_{ax}'});
x = reordercats(x,{'Rotor only','200% C_{ax}','100% C_{ax}','50% C_{ax}','25% C_{ax}'});
y = [4.521,1.5605,1.4531,1.3533,1.3528]*(1e-5);
%y = [4.521,1.5605,1.4531,1.3533,1.3528]*(1e-5);
%z = [70.0774,13.3098,6.9025,0.0369,0];
hb = bar(x,y)
%text([1:length(y)], z, num2str(z),'HorizontalAlignment','center','VerticalAlignment','bottom')
numbersToAdd = [70.0774,13.3098,6.9025,0.0369,0];
barWidth = hb.BarWidth;
numCol = size(M,2);
cnt = 0;
for ii = numbersToAdd'
cnt = cnt + 1;
xPos = linspace(cnt - barWidth/2, cnt + barWidth / 2, numCol+1);
idx = 1;
for jj = xPos(1:end-1)
val = numbersToAdd(cnt,idx);
y = M(cnt,idx);
text(jj, y + 1, num2str(val));
idx = idx +1;
end
end
box on
grid on
ylabel("Work on the blade, J")
댓글 수: 0
채택된 답변
Dyuman Joshi
2023년 3월 27일
clear all
close all
clc
x = categorical({'Rotor only','200% C_{ax}','100% C_{ax}','50% C_{ax}','25% C_{ax}'});
x = reordercats(x,{'Rotor only','200% C_{ax}','100% C_{ax}','50% C_{ax}','25% C_{ax}'});
y = [4.521,1.5605,1.4531,1.3533,1.3528]*(1e-5);
z = [70.0774,13.3098,6.9025,0.0369,0];
hb = bar(x,y);
text(x,y,string(z),'HorizontalAlignment','center','VerticalAlignment','bottom')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
