如何在matlab中对错误条单独着色?

如何在matlab中对错误条单独着色?,matlab,Matlab,我想在Matlab中分别为错误条着色,但似乎无法理解。Luis Mendo在2015年的一篇类似帖子和回答中推荐了下面的代码,但这种方法已经过时,并且不起作用,因为错误条的子对象现在是0x0占位符 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),'colo

我想在Matlab中分别为错误条着色,但似乎无法理解。Luis Mendo在2015年的一篇类似帖子和回答中推荐了下面的代码,但这种方法已经过时,并且不起作用,因为错误条的子对象现在是0x0占位符

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

这不是有史以来最优雅的事情,但您可以使用所需颜色的标准线图在errorbar图上绘制:

clc; clear all;

x=1:100;
y=rand(length(x),1);
e(1:length(x))=1;

h = errorbar(x,y,e,'r')
hold on;
plot(x,y,'b');

这不是最优雅的事情,但您可以使用标准的线图和所需的颜色在errorbar图上绘制:

clc; clear all;

x=1:100;
y=rand(length(x),1);
e(1:length(x))=1;

h = errorbar(x,y,e,'r')
hold on;
plot(x,y,'b');

如果要使每个错误栏具有不同的颜色,基本上可以重新创建错误栏打印功能,并根据与每个特定点相关的错误按比例缩放颜色:

clc; clear all;

x=1:30;
y=rand(length(x),1);
e=rand(length(x),1);

plot(x,y,'k');hold on;

max(e);
range=min(x)-max(x);
inc=range/100;
for i=1:length(x)
    c=[e(i)/max(e) (max(e)-e(i))/max(e) 0];
    plot([x(i) x(i)],[y(i)-e(i) y(i)+e(i)],'Color',c);
    plot([x(i)-inc x(i)+inc],[y(i)-e(i) y(i)-e(i)],'Color',c);
    plot([x(i)-inc x(i)+inc],[y(i)+e(i) y(i)+e(i)],'Color',c);
end

如果要使每个错误栏具有不同的颜色,基本上可以重新创建错误栏打印功能,并根据与每个特定点相关的错误按比例缩放颜色:

clc; clear all;

x=1:30;
y=rand(length(x),1);
e=rand(length(x),1);

plot(x,y,'k');hold on;

max(e);
range=min(x)-max(x);
inc=range/100;
for i=1:length(x)
    c=[e(i)/max(e) (max(e)-e(i))/max(e) 0];
    plot([x(i) x(i)],[y(i)-e(i) y(i)+e(i)],'Color',c);
    plot([x(i)-inc x(i)+inc],[y(i)-e(i) y(i)-e(i)],'Color',c);
    plot([x(i)-inc x(i)+inc],[y(i)+e(i) y(i)+e(i)],'Color',c);
end

查看旧问题(2014年起,不确定是否为您所指的问题)副本中有更新的答案。查看旧问题(2014年起,不确定是否为您所指的问题)副本中有更新的答案。