Error bars for every other bar

2 visualizaciones (últimos 30 días)
Andre White
Andre White el 14 de Dic. de 2022
Comentada: Andre White el 14 de Dic. de 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

Respuesta aceptada

Dave B
Dave B el 14 de Dic. de 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)

Más respuestas (0)

Categorías

Más información sobre Bar Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by