How do I change the width of the horizontal lines at top and bottom of error bars in my Errorbar plot?
조회 수: 5 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2009년 6월 27일
편집: MathWorks Support Team
2016년 6월 23일
For example, how can I increase the width of each of the error bars in the following plot:
figure;
X = 0:pi/10:pi;
Y = sin(X);
E = std(Y)*ones(size(X));
errorbar(X,Y,E);
채택된 답변
MathWorks Support Team
2016년 6월 23일
In MATLAB R2016b, this can be accomplished using the ‘CapSize’ property of the Errorbar plot. The following code illustrates how to do this:
x = 0:pi/10:pi;
y = sin(x);
e = std(y)*ones(size(x));
figure
h = errorbar(x,y,e);
h.CapSize = 12;
In MATLAB versions R2014b through R2016a, this functionality is not present.
In MATLAB R2014a and earlier, you can change the width of these horizontal lines by modifying the ‘Xdata’ of each of them. The following code illustrates how to do this in an automated fashion:
hf = figure;
X = 0:pi/10:pi;
Y = sin(X);
E = std(Y)*ones(size(X));
ha = errorbar(X,Y,E);
hb = get(ha,'children');
Xdata = get(hb(2),'Xdata');
temp = 4:3:length(Xdata);
temp(3:3:end) = [];
% xleft and xright contain the indices of the left and right
% endpoints of the horizontal lines
xleft = temp; xright = temp+1;
% Increase line length by 0.2 units
Xdata(xleft) = Xdata(xleft) - .1;
Xdata(xright) = Xdata(xright) + .1;
set(hb(2),'Xdata',Xdata)
댓글 수: 0
추가 답변 (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!