How do I get values on top of my bar plot?
1 view (last 30 days)
Show older comments
I have data that I want to have shown in groups of three. How can I get the values Diff onto the bar plot? I have tried various ways but can't get it right...
Diff = [minD1 maxD1 meanD1; minD maxD meanD; minD2 maxD2 meanD2; minD3 maxD3 meanD3; minD4 maxD4 meanD4]*10^4;
figure
name = categorical({'100 ul', '200 ul', '500 ul', '750 ul', '1000 ul'});
name = reordercats(name,{'100 ul', '200 ul', '500 ul', '750 ul', '1000 ul'});
bar(name, Diff)
ylabel('Diffusion coefficent (10^-^4)')
legend('min D','max D','mean D')
grid on
grid minor
4 Comments
Accepted Answer
Ameer Hamza
on 15 Jun 2020
See this example
% Diff = [minD1 maxD1 meanD1; minD maxD meanD; minD2 maxD2 meanD2; minD3 maxD3 meanD3; minD4 maxD4 meanD4]*10^4;
Diff = rand(5, 3);
name = {'100 ul', '200 ul', '500 ul', '750 ul', '1000 ul'};
figure;
ax = axes();
b = bar(1:5, Diff);
ylabel('Diffusion coefficent (10^-^4)')
legend('min D','max D','mean D')
grid on
grid minor
ax.XTickLabel = name;
barNames = {'a', 'b', 'c'};
x_diffs = [-0.25 -.05 0.2]; % x-location of bars relative to middle bar
y_diff = 0.02; % height of text above the bar
for i = 1:numel(b)
text(b(i).XData+x_diffs(i), b(i).YData+y_diff, barNames(i));
end

4 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!