Rac*_*hel 2 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)
Run Code Online (Sandbox Code Playgroud)
没有内置和记录的方法来执行此操作.但是,您可以使用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)) = [];
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用以下内容更改上盖和下盖的宽度.
% 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;
Run Code Online (Sandbox Code Playgroud)
注意:此确切答案仅适用于R2014b - R2015b.在2016a中,Mathworks改变了使用方式,
LineStrip因此VertexData属性不是上面显示的格式.