Different size error bar caps
Show older comments
I wish to make a bar chart with 5 bars with error bars on only two of these bars. My current code is
bounds=categorical({'aa','bb','cc','dd','ee'});
vals=[1,2,3,4,5]
set(gca,'TickLabelInterpreter','latex','Fontsize',18);
ylabel('Variance','Fontsize',20)
%
% pause(2)
colors = [0 0 1;
1 0 0;
1 0 0;
0 1 0;
0 1 0];
alphas = [1,0.3,1,0.3,1];
b = gobjects(size(bounds));
cla()
hold on
for i =1:numel(bounds)
b(i)=bar(bounds(i),vals(i));
if rem(i,2)==0
line='--';
else
line='-';
end
set(b(i),'FaceColor',colors(i,:),'FaceAlpha',alphas(i),'LineStyle',line);
end
ehigh=[0,0.5,0,0.8,0]
elow=ehigh;
hold on
er = errorbar(bounds,vals,elow,ehigh,'k','LineStyle','none');
er.Color = [0 0 0];
er.LineStyle = 'none';
er.LineWidth=1;
er(1).CapSize=20;
which almost does what I want, however I can still see the zero error bar in the three bars with no error. I can get rid of this by setting the capsize to 0 but I don't really want this as then I have no caps on the error bars that I do want. Is there a way to set the error bar cap sizes differently for each point?
Or equally good would be a way to only have error bars on certain bars.
Many thanks!!
Accepted Answer
More Answers (0)
Categories
Find more on Bar 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!