首页 > 解决方案 > 如何在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),'color','g') %// error bars

标签: matlab

解决方案


这不是最优雅的事情,但您可以使用具有所需颜色的标准线图绘制误差条图:

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');

在此处输入图像描述


推荐阅读