Errorbar on Box and Whisker Plot
44 次查看(过去 30 天)
显示 更早的评论
I am confused on how I can add error bars to my box and whisker plot:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/689638/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/689643/image.png)
0 个评论
回答(1 个)
Ive J
2021-7-22
编辑:Ive J
2021-7-23
If you want error bars on the same box plots, you can use something like this:
tab = table(randi([1, 50], 20, 1), repmat([1; 2], 10, 1), 'VariableNames', {'value', 'group'}); % sample data with 2 groups: 1 and 2
hold on
boxchart(tab.group, tab.value)
% update the boxchart with data points + errorbars
for i = 1:2
y = tab.value(tab.group == i);
x = ones(sum(tab.group == i), 1).*i;
plot(x, y, 'o', 'MarkerFaceColor', 'r') % first show data points
errorbar(i, mean(y), mean(y)+std(y), 'Marker', 'o', 'MarkerFaceColor', 'k', 'Color', 'k') % then show error around the mean value only
end
2 个评论
Ive J
2021-7-23
So take a look at my edited snippet. Error in this case is only shown around the mean.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!