CapSize for a customized errorbar plot
21 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!