Adding Error Bars to a grouped Bar Plot
6 次查看(过去 30 天)
显示 更早的评论
hey,
i have tried a few of the other answers to similar problems however i come into an issue where the error bars are all drawn together.
here is my code, any advice would be helpful
i am using matlab 2018a
% my data is WUSW, the group labels are X, the errors are WerrL & WerrH
% respectively
WUSW = [0.22 0.18;0.21 0.08; 0.22 0.14; 0.25 0.13];
X = categorical({'Flat','Lotus','Lines','Sharklet'});
X = reordercats(X,{'Flat','Lotus','Lines','Sharklet'});
WerrL = [0.01 0.06 0.03 0.06; 0.03 0.04 0.04 0.02];
WerrH = [0.02 0.03 0.03 0.04; 0.03 0.03 0.03 0.06];
%here is the code i adapted from the other answers to problems
figure
hBar = bar(WUSW, 0.8); % Return ‘bar’ Handle
for k1 = 1:size(WUSW,2)
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, hBar(k1).XOffset'); % Note: ‘XOffset’ Is An Undocumented Feature, This Selects The ‘bar’ Centres
ydt(k1,:) = hBar(k1).YData; % Individual Bar Heights
end
hold on
errorbar(ctr, ydt, WerrL, WerrH)
%when i do this all the error bars display correctly but are connected like
%a daisy chain
0 个评论
回答(2 个)
Star Strider
2021-4-20
Change the errorbar call slightly to:
errorbar(ctr, ydt, WerrL, WerrH, '.', 'MarkerSize',0.25)
That should do what you want.
0 个评论
Andrew Frane
2024-11-24
To make error bars without a connecting line, just set the 'LineStyle' to 'none', using a name-value pair in the errorbar command:
errorbar(ctr, ydt, WerrL, WerrH, 'LineStyle', 'none')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!