필터 지우기
필터 지우기

Add text above grouped bars

조회 수: 1 (최근 30일)
Jesper Nielsen
Jesper Nielsen 2019년 11월 12일
댓글: Jesper Nielsen 2019년 11월 12일
Hi!
I found a code that adds the numerical values of my bars above the bars in my plot, but I want to add a %-sign after the values, to highlight that the values are measured in percentage.
y1 = [0.0 3.3; 4.8 7.7; 19.3 6.6; 49.4 35.2; 26.5 47.3];
hBar = bar(y1,1);
for k1 = 1:size(y1,2)
ctr(k1,:) = bsxfun(@plus, hBar(1).XData, hBar(k1).XOffset');
ydt(k1,:) = hBar(k1).YData;
text(ctr(k1,:), ydt(k1,:), sprintfc('%.1f', ydt(k1,:)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom', 'FontSize',14, 'Color','black')
end
untitled.jpg
Is there any way to do this?
Thank you in advance.

채택된 답변

Praveen Iyyappan Valsala
Praveen Iyyappan Valsala 2019년 11월 12일
'%%' is the escape sequence for percentage symbol as shown here.
sprintfc('%.1f %%', ydt(k1,:))
  댓글 수: 1
Jesper Nielsen
Jesper Nielsen 2019년 11월 12일
You are my hero. Thank you.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by