# CapSize for a customized errorbar plot

24 views (last 30 days)
Pankaj on 26 Aug 2019
I am writing a customized errorbar for myself. But I do not know how to control the CapSize, like it is controled in the default errorbar; zooming-in or zooming-out doesnot enlarge the Cap. A simplified version of my code is as follow-
function myErrorbar(x, y, h)
for i = 1:length(x)
y1 = y(i)-h(i);
y2 = y(i)+h(i);
x1 = x(i)-0.1*h(i);
x2 = x(i)+0.1*h(i);
% errorbar
line([x(i), x(i)], [y1, y2]); hold on
% caps
line([x1, x2], [y1, y1])
line([x1, x2], [y2, y2])
end
In the above code I have fixed the size of caps equal to 10% of h on either sides. I want to control the capsize like it could be done in the default. The code could be tested with following code
x = 1:10:100;
y = [20 30 45 40 60 65 80 75 95 90];
err = 8*ones(size(y));
myErrorbar(x,y,err)
thanks

Dinesh Yadav on 29 Aug 2019
As of now, there is no method at present for controlling CapSize using line plot. You can write your custom code only to make caps using line plot. However, you can use
errorbar(x,y,err,'.','CapSize',x);
where x is the size of Cap you want. This way your plot would look identical except for a small ‘.’ Dot marker in the center of each line. I have implemented your code in MATLAB 2019a on Windows PC and zooming in and out enlarges and decrease the size of Cap as expected.

R2016b

### Community Treasure Hunt

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

Start Hunting!