如何在Matlab中分离颜色误差条

8

给定以下示例代码:

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

figure
errorbar(x,y,e)

你是如何将这条线与水平线区分开来的?

我尝试了

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

但这会同时改变它们所有的属性...
2个回答

11

获取errorbar对象的句柄。它有两个子元素,分别对应于数据图和误差条。然后您可以单独设置每个颜色。

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

太棒了,这比那些琐碎的代码行规范简单多了。 - user1234440

3
在2014b版本中,误差条对象不再有子级。一个(丑陋的)解决方法是使用不同颜色重新绘制函数一次。 实际上,这会在旧颜色的函数上方使用新颜色绘制该函数。
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

2
你可以完全隐藏errorbar中的线图:errorbar(x, y, e, 'r', 'LineStyle', 'none'); - Dominik

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接