删除错误图中的下标记

时间:2016-12-28 19:32:46

标签: matlab matlab-figure

我试图在MATLAB中绘制单侧错误图。这是示例代码和输出。我想删除用红色圈出的标记。有人可以帮帮我吗?

x = 1:10;
X1=rand(13,10);
y = mean(X1);
U= std(X1);
L=zeros(size(y));
errorbar(x,y,L,U,'--k','LineWidth',2)

Sample output

1 个答案:

答案 0 :(得分:6)

没有内置和记录的方法来执行此操作。但是,您可以使用Bar对象的未记录ErrorBar属性,该对象是LineStrip对象。然后,您可以删除此LineStrip对象的顶点,这些顶点对应于条形的底部。

% Create a normal errorbar plot
e = errorbar(x,y,L,U,'--k','LineWidth',2);

% This is needed on Windows to ensure that the VertexData property is populated
drawnow

% Remove the line strip vertices which correspond to the bottom bars
e.Bar.VertexData(:,(numel(x)*2 + 1):(numel(x) * 4)) = [];

enter image description here

或者,您可以使用以下内容更改上限和下限的宽度。

% Create a normal errorbar plot
e = errorbar(x,y,L,U,'--k','LineWidth',2);

% This is needed on Windows to ensure that the VertexData property is populated
drawnow

% [lower_cap_size, upper_cap_size]
cap_sizes = [0, 0.1];

vd = e.Bar.VertexData;

% Create alternately 1's and -1's to add to multiply by the width and add
% to the bar centers
diffs = 1-mod(1:(numel(x) * 2),2)*2;

% Determine the differences relative to the center of each bar for the 
% lower and upper caps
lowers = diffs * (0.5 * cap_sizes(1));
uppers = diffs * (0.5 * cap_sizes(2));

% Replace the vertex data for the caps by adding the above differences
% to the bar centers
vd(1,(numel(x)*2 + 1):end) = repmat(vd(1,1:numel(x)*2), [1 2]) + [lowers, uppers];

% Assign the vertex data back
e.Bar.VertexData = vd;
  

注意:此完全答案仅适用于R2014b - R2015b。在2016a中,Mathworks改变了使用LineStrip的方式,因此VertexData属性不是上面显示的格式。