How to put a numerical value inside a Bar graph?
62 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sara Macchiavello
am 29 Nov. 2020
Kommentiert: Star Strider
am 29 Nov. 2020
Hi!
I'd like to know how can I set the values inside the bar plot, just like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/433973/image.jpeg)
I obtain the following bar plot using the code above but I can't place values in the correct center position.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/433978/image.jpeg)
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
1 Kommentar
Akzeptierte Antwort
Star Strider
am 29 Nov. 2020
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/433993/image.png)
.
4 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Bar Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!