Different size error bar caps
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lorcan Conlon
il 27 Set 2020
Commentato: Lorcan Conlon
il 30 Set 2020
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!!
0 Commenti
Risposta accettata
Prudhvi Peddagoni
il 30 Set 2020
Hi Lorcan,
You can set the linewidth for both bar and error bar to 1. So that you won’t see the thickness on the bars that you don’t want to see the error bars on.
Other thing to do is to declare another set of bounds and vals variables so that you can specify error bars for only those two bars like this.
ehigh = [0.5,0.8];
elow = ehigh;
hold on;
bound = [bounds(2) bounds(4)];
values = [vals(2) vals(4)];
er = errorbar(bound, values, elow, ehigh, 'k', 'LineStyle', 'none');
Hope this helps.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Discrete Data Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!