필터 지우기
필터 지우기

How to put a numerical value inside a Bar graph?

조회 수: 62 (최근 30일)
Sara Macchiavello
Sara Macchiavello 2020년 11월 29일
댓글: Star Strider 2020년 11월 29일
Hi!
I'd like to know how can I set the values inside the bar plot, just like this:
I obtain the following bar plot using the code above but I can't place values in the correct center position.
b = bar(X,Y);
hold on
b.FaceColor = 'flat';
b.CData(1,:) = [0 0.447 0.741]; % color editing
b.CData(2,:) = [0.850 0.325 0.098];
b.CData(3,:) = [0.466 0.674 0.188];
b.FaceAlpha = .7; % opacity
text(1:length(Y),Y,num2str(Y'),'vert','bottom','horiz','center'); % values position
std = [2.1 4.4 6]; % standard deviation
er = errorbar(X,Y,std);
er.Color = [0 0 0];
er.LineStyle = 'none';
set(gca, 'ytick', []);
box off
Can you help me, please?
Thank you,
Sara

채택된 답변

Star Strider
Star Strider 2020년 11월 29일
Change the text call to:
text(1:length(Y),Y/2,num2str(Y'),'vert','bottom','horiz','center'); % values position
That should work, if I understand correctly what you want to do.
.
  댓글 수: 4
Sara Macchiavello
Sara Macchiavello 2020년 11월 29일
Thank you very much for your advice and explaination, you're really kind!!
Star Strider
Star Strider 2020년 11월 29일
As always, my pleasure!
I very much appreciate your compliment!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by