Grouped bar graph with individual datapoints
Show older comments
I am trying to plot a grouped bar graph with error bars and individual datapoints. I was able to do the bargraph with errorbars. How can I add individual data points to each bar?
figure
model_series = [mean(Dat_100_200_E_M,1); mean(Dat_100_200_M_E,1)];
model_error = [std(Dat_100_200_E_M)/sqrt(length(Dat_100_200_E_M)); std(Dat_100_200_M_E)/sqrt(length(Dat_100_200_M_E))];
b=bar(model_series, 'grouped','FaceColor','flat');
legend ('boxoff');
b(1).CData = [[1 0 0]; [1 0 0]];
b(2).CData = [[1 1 0]; [1 1 0]];
ylim([0 6]);
hold on
nbars = size(model_series, 2);
x = [];
for i = 1:nbars
x = [x ; b(i).XEndPoints];
end
errorbar(x',model_series,model_error,'k','LineWidth', 1.5,'linestyle','none','HandleVisibility','off');
hold off
box off
ax = gca;
set(gca,'xticklabel',{'Left', 'Right'});
ylabel('Amplitude','FontSize', 12)

2 Comments
What data points do you want added and how to look?
plot() works after where you are now...if you do it before the hold off command...aftter that and you'll wipe the slate clean first. Allthough line would work it's lower-level...
I'd also recommend to save the handles to the plot objects; never know when may want to add some niceties; keeping the handle around lets you do that -- plus also can use them for legend
Varghese
on 30 Jul 2021
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots 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!
