Control errorbar width in Matlab R2014b

2 次查看(过去 30 天)
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 个评论
Trevor Agus
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!
Brandon  Madsen
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
Sean de Wolski 2015-1-7
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
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
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
Sören Fechner 2015-1-30
I have the same Problem. Have you found a solution yet ?

Ramaprasad Kulkarni
Ramaprasad Kulkarni 2016-12-20
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
Scott Webster 2017-3-3
Wouldn't that result in inconsistent crossbar widths though, if they were scaled with the x position value?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Errorbars 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by