MATLAB: Best estimate with range bar charts

bar plotsrange bars

How to plot a bar chart with range bars over the top like the figure shown.
Thanks in advance !

Best Answer

Hi A Aravinda,
It is my understanding that you are trying to overlay the range bars over your bars in your bar chart. This can be done by using the errrorbar function along with the annotations and bar functions.
The following code is an example,
x = 1:2:3;
data = 2.*x;
errhigh = [0.5 0.5]; %range bars
errlow = [0.5 0.5];
b = bar(x,data,0.1) ;
xtips1 = b(1).XEndPoints;
ytips1 = b(1).YEndPoints;
A = x+errhigh;
B = x-errlow;
lablea = 'Range = ' + string(B(1))+'-' + string(A(1));
lableb = 'Range = ' + string(B(2))+'-' + string(A(2));
text(xtips1,ytips1,[lablea,lableb],'HorizontalAlignment','center',...
'VerticalAlignment','bottom
hold on
er = errorbar(x,data,errlow,errhigh,'horizontal');
er.Color = [0 0 0];
er.LineStyle = 'none';
hold off
Hope this Helps
Kiran Felix Robert