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...
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
In 2014b the error bar object doesn't have children anymore. One (ugly) way of circumventing this is to plot the function again with a different color. Effectively this plots the function with a new color on top of the function with the old color.
hold on;
errorbar(x, y, e, 'r'); % // The color here will stay for the error bars
plot(x, y, 'b'); %// Here we change the color of the original function
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