How to separate color errorbar matlab

user1234440 picture user1234440 · Apr 2, 2014 · Viewed 13.2k times · Source

Given the following example code:

x = 0:pi/10:pi;
y = sin(x);
e = std(y)*ones(size(x));

figure
errorbar(x,y,e)

How are you able to color the line different compared to the horizontal lines?

I tried

errorbar(x,y,e,'--mo')

But this changes all of them together...

Answer

Luis Mendo picture Luis Mendo · Apr 2, 2014

Get a handle to the errorbar object. It has two children, corresponding to the data plot and error bars respectively. Then you can set the color of each separately.

h = errorbar(x,y,e) %// a color spec here would affect both data and error bars
hc = get(h, 'Children')
set(hc(1),'color','b') %// data
set(hc(2),'color','g') %// error bars