Control errorbar width in Matlab R2014b
이전 댓글 표시
Pre R2014b Matlab versions allowed the separate control of the length of the top and bottom error bar lines separately through the 'xdata' property. This is not possible any more in Matlab R2014b, where the 'xdata' property contains only the x coordinates of the data points but not the error bar lines. Is there a way to control the error bar line length in Matlab R2014b?
댓글 수: 8
Scott Webster
2014년 12월 21일
I have this same question, and also wonder if anyone knows how the "automatic" tick width is determined?
Oleg Komarov
2015년 1월 3일
Have you checked the LData/UData and LDataSource/UDataSource properties?
Scott Webster
2015년 1월 5일
Perhaps it is ambiguous, but the line width that I wish to control is the little endpoint line at the limits of the error bars, not the actual size of the error bars themselves. As shown by the red arrows here:

The LData/UData seem to just contain the usual length of the actual lower and upper error bars, and the LDataSource/UDataSource properties are empty because the errors have been specified directly rather than through a workspace variable...
If the OP actually wanted to be able to just specify different sized lower/upper errors, than that is a different question than mine and I would imagine be addressed through seeting LData and UData.
Oleg Komarov
2015년 1월 7일
There was definitely no control over the length of the end lines. You can get it through an undocumented property with R2014b, but it is not trivial.
Scott Webster
2015년 1월 7일
I'm pretty sure this was possible pre-2014b, but I think it was also undocumented. Part of the reason for wanting control is that the automatic algorithm Matlab uses to determine the width is unclear... so when making a series of plots, sometimes those end lines are not the same length, so the plots are inconsistent.
Axel
2015년 1월 14일
It was possible in versions before R2014b. And I stuck with the same problem...
Trevor Agus
2015년 8월 2일
I've made a temporary solution to the problem by avoiding using the original "errorbar" function, and writing my own "terrorbar.m" that just draws the lines (using plot) as required.
It has the kinds of features needed by that those of us who might care about the width of our confidence intervals, i.e., you can specific the width in absolute terms (e.g. 'centi', 'inches') or normalised to the size of the figure ('norm') or to the units ('units').
It copes with changes in figure size, but not necessarily other changes (units, axis size), unless you re-call the function after (no parameters required). This is not ideal, but it's about as good as you'll get without hacking into the darkest depths of Matlab!
You can download it through Matlab Central: http://uk.mathworks.com/matlabcentral/fileexchange/52367-terrorbar-m--error-bars-with-controlled-widths-post-r2014b
Brandon Madsen
2018년 1월 25일
편집: Brandon Madsen
2018년 1월 25일
See 1/25/2018 answer here ( https://www.mathworks.com/matlabcentral/answers/100333-how-do-i-change-the-width-of-the-horizontal-lines-at-top-and-bottom-of-error-bars-in-my-errorbar-plo ) for a version that I think should work for 2014b (it works for 2015b for sure). It involves hacking into the darkest depths of Matlab, as suspected ;)
답변 (3개)
Sean de Wolski
2015년 1월 7일
4 개 추천
Pre-R2014b, this was possible because the errorbar series had children which were lines you could adjust. Since that's no longer the case, this approach no longer works.
I'd at least recommend contacting tech-support with your use-case and reasoning so that they can add an enhancement request for it.
댓글 수: 5
Scott Webster
2015년 2월 3일
I think I have finally come up with a decent minimal working example. I will submit the following to support and see what they say.
x=[5 25];
y=[10 10];
err=[5 5];
hold on
errorbar(x,y,err,'ro');
x=[13 17];
errorbar(x,y,err,'bo');
print('-dpng','errorbars.png');
The above code generates the following plot. As you can see, the blue points, which are closer together, have zero-width top/bottom crossbars.

Scott Webster
2015년 2월 3일
I got a reply from support. They said that they submitted a high priority enhancement request to address this issue and suggested a workaround. Apparently the crossbar width is set to be 2% of the total horizontal range of the data, so when you have data sets with different ranges, you get different results. The workaround is to add "dummy" data points to each of your data sets, and then set the plot limits so they are not shown. For example, the following code generates the plot below.
x=[-1 5 25 31];
y=[10 10 10 10];
err=[0 5 5 0];
hold on
errorbar(x,y,err,'ro');
x=[-1 13 17 31];
errorbar(x,y,err,'bo');
xlim([0 30]);
print('-dpng','errorbars2.png');

pedro
2017년 1월 26일
Any news regarding this high priority enhancement? I have a problem this workaround doesn't solve. The crossbars are too wide, and overlap the neighboring bars. This workaround actually makes the problem worse, since the crossbar width is a fixed % of the total horizontal range of the data, regardless of the number of bars.
Scott Webster
2017년 3월 7일
I replied to my Mathworks support case on this (2 years old) 4 days ago. No reply yet. I'll update here if I get an answer.
Scott Webster
2017년 3월 14일
I received a response from MathWorks. A CapSize property has been added to the errorbars as of R2016b. Here is my previous example updated to use this functionality (with excessive crossbar width):
x=[5 25];
y=[10 10];
err=[5 5];
hold on
h=errorbar(x,y,err,'ro');
h.CapSize = 12;
x=[13 17];
h=errorbar(x,y,err,'bo');
h.CapSize = 12;
print('-dpng','errorbars3.png');
The resultant plot is as follows.

However, I also noticed that the errorbar width was actually ok for this example in R2016b before I even adjusted the capsize, so it seems that some other general improvements were made as well.
Finally, MathWorks also provided the following code example for manually drawing the crossbars in case you don't have R2016b.
% Create errorbar
X = 0:pi/10:pi;
Y = sin(X) + 1;
E = std(Y) * ones(size(X));
ha = errorbar(X, Y, E);
% Width of the top and bottom lines of errorbar
xlength = 0.1;
% Make horizontal lines with 'line'
for k = 1:length(X)
x = [X(k) - xlength, X(k) + xlength];
y_h = [Y(k) + E(k), Y(k) + E(k)];
line(x, y_h);
y_b = [Y(k) - E(k), Y(k) - E(k)];
line(x, y_b);
end
Sören Fechner
2015년 1월 30일
0 개 추천
I have the same Problem. Have you found a solution yet ?
Ramaprasad Kulkarni
2016년 12월 20일
0 개 추천
You guys might have found a solution, but just putting this out there:
An alternate and easier option to control the width of the top/bottom crossbars is to plot each pair of [x(i), y(i)] points and corresponding errorbar(x(i),y(i),err(i)). This ensures the width of the top/bottom crossbars is 0.02*x(i).
The downside of this approach is you have to use an unnecessary for loop to go over all the values in the X/Y vectors.
댓글 수: 1
Scott Webster
2017년 3월 3일
Wouldn't that result in inconsistent crossbar widths though, if they were scaled with the x position value?
카테고리
도움말 센터 및 File Exchange에서 Errorbars에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!