How to separate color errorbar matlab

五迷三道 提交于 2021-02-16 06:55:53

问题


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...


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/22797919/how-to-separate-color-errorbar-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!