MATLAB Answers


How can I create horizontal error bars in MATLAB?

The "errorbar" function can only create error bars in the vertical direction, but I would like to create horizontal ones.




2 Answers

Answer by MathWorks Support Team on 20 Jun 2017
Edited by MathWorks Support Team on 20 Jun 2017
 Accepted Answer

The ability to create horizontal error bars was added in MATLAB R2016b. You can specify the "ornt" (orientation) property of the plot to be "horizontal" to generate horizontal error bars. 
For release R2016a or older
The ability to create horizontal error bars is not available in previous releases. As a workaround, you can download the user-contributed "herrorbar" function from the MATLAB Central File Exchange. You can find this file at the following URL:
Note that MathWorks does not guarantee or warrant the use or content of these submissions. Any questions, issues, or complaints should be directed to the contributing author.


The errorbar function help page explicitly states that there is an orientation option 'ornt' that should be able to force it to use horizontal errorbars instead of vertical ones. There are even examples given. However in practice this does not work. If this functionality truly isn't supposed to be there might I suggest removing that portion of the help page?
Dan, which version of MATLAB are you using? 'ornt' as added in 2016b, the original question was about 2016a.

Sign in to comment.

Answer by Vahab Youssofzadeh on 19 Jul 2016

You can try,
view([90 -90]).
Here's an example,
m = [1,2,3]; e = [0.5,1,0.3];
label = {'s1','s2','s3'};
set(gca,'Xtick', 1:3,'XtickLabel',label);
view([90 -90])

  1 Comment

... that flips the whole plot, which doesn't accomplish horizontal error bars in the manner they clearly want?

Sign in to comment.