MATLAB Answers


CapSize for a customized errorbar plot

Asked by Pankaj
on 26 Aug 2019
Latest activity Answered by Dinesh Yadav on 29 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])
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));


Sign in to comment.




1 Answer

回答者: Dinesh Yadav 2019 年 8 月 29 日

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
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.


Sign in to comment.