Adding error bars to a grouped bar plot
이전 댓글 표시
Hi! I’m trying to plot a grouped bar graph with standard errors, and have managed this so far, which almost works but the SE are for some reasons plotted next to the bars rather than on them (see attached)? Any idea how to fix it? Thanks!

err = [3, 3; 1, 3];
y=[69,123; 74, 62];
figure
bar(y)
set(gca, 'XTickLabel', {'Cats' 'Dogs'});
hold on
errorbar(y, err, '.')
ylabel('Mean Error');
ylim([20 140]);
legend('response to novel cats', 'response to novel dogs');
saveas(gcf,['bar_2', '.jpg'])
채택된 답변
추가 답변 (2개)
Steve Schaefer
2020년 3월 11일
6 개 추천
The code to create the below shown picture can be found in this MATLAB Answer:

댓글 수: 2
Jonathan Cottet
2021년 4월 19일
The code for the graph is not really displayed in the link you posted (categorical graph in your picture). Could you please post it here ?
Thanks in advance !
z8080
2023년 6월 20일
@Steve Schaefer, I would second @Jonathan Cottet's request to please post that code, as it is in fact not to be found under the given link. Thanks!
Star Strider
2023년 6월 20일
0 개 추천
An example using properties available in prior and recent MATLAB releases is provided in Putting error bars on bar plot?
One of these approaches should work for all releases (at least after R2014b when ‘Handle Graphics 2’ appeared, and perhaps for earlier releases as well). The same general approach will also work for putting numbers or other text objects above or within the bars.
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!