This is my problem:

I have a MATLAB plot with errorbar (all work right), but the width of the bars is too wide. There is a way to set the width of the bar?
If you look this image very carefully, you can see several lines reds and blues with the size that I would like (e.g., w = 0.25).
Any help is appreciate.
You need to access their XData property and modify them. Check here for an example by The Mathworks.
Concretely here is how to do it:
Generate an errorbar plot:
hf = figure;
X = 0:pi/10:pi;
Y = sin(X);
E = std(Y)*ones(size(X));
hErrBar = errorbar(X,Y,E);
Get the XData property as well as the left/right indices representing the horizontal lines of the error bars.
hb = get(hErrBar,'children');
Xdata = get(hb(2),'Xdata');
temp = 4:3:length(Xdata);
temp(3:3:end) = [];
xleft = temp; xright = temp+1;
Modify the data as you wish and update the plot. For example, decrease the line length by 0.2 units
Xdata(xleft) = Xdata(xleft) + .1;
Xdata(xright) = Xdata(xright) - .1;
%// Update
set(hb(2),'Xdata',Xdata)
So for example,
Before:

And after:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With