CapSize for a customized errorbar plot

조회 수: 25 (최근 30일)
Pankaj
Pankaj 2019년 8월 26일
답변: Dinesh Yadav 2019년 8월 29일
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

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by