Error bars for every other bar

4 vues (au cours des 30 derniers jours)
Andre White
Andre White le 14 Déc 2022
Commenté : Andre White le 14 Déc 2022
Hi everyone:
I am trying to set an error bar on every other bar. The error bar goes where each tick label is located. I am using the following code:
figure
x=1:4;
o_tip=[10.6,0.5300,1.3158,5.3300];
lower=[0.1900, 0.0500,0.0478, 1.3500];
upper=[ 0.1200, 0.0600, 0.0942, 1.4400];
kap=[10.0000,0.5000,3.4000,4.4000];
b=bar(x,[o_tip;kap]);
hold on
er=errorbar(x,o_tip,lower,upper);
%er.Color = [0 0 0];
er.LineStyle = 'none';
Can you please help me to solve this problem?
Thank you

Réponse acceptée

Dave B
Dave B le 14 Déc 2022
I think what you're trying to do is put the errorbars on the first bar series? You can do this using the XEndPoints from the bar, which include not only the x values but the offset that's used by bar to make the grouped bar chart:
x=1:4;
o_tip=[10.6,0.5300,1.3158,5.3300];
lower=[0.1900, 0.0500,0.0478, 1.3500];
upper=[ 0.1200, 0.0600, 0.0942, 1.4400];
kap=[10.0000,0.5000,3.4000,4.4000];
b=bar(x,[o_tip;kap]);
hold on
er=errorbar(b(1).XEndPoints,o_tip,lower,upper);
er.Color = [0 0 0];
er.LineStyle = 'none';
(If you then want to put errorbars on the second series, just use b(2) in place of b(1), to get the middle of the orange bars)
  1 commentaire
Andre White
Andre White le 14 Déc 2022
Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Errorbars dans Help Center et File Exchange

Tags

Produits


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by