%% % exp1 blue=[80/255 138/255 178/255]; %画出bar图 x = categorical({'600','5','1'}); y=[-52.470 -33.936 -24.414]; err=[2.731 2.731 2.827]; ci = 1.96 .* err ./ sqrt(numel(y)); % 计算置信区间 b1=bar(x,y); hold on; %添加置信区间 for i = 1:numel(y) errorbar(i, y(i), ci(i), 'k', 'linestyle', 'none'); end hold on; %添上数据标签 xtips = b1.XEndPoints; ytips = b1.YEndPoints; labels = string(b1.YData); text(xtips,ytips,labels,'HorizontalAlignment','center','VerticalAlignment','bottom') %添加坐标轴标签 xlabel('kappa','Fontname','Times New Roman','Fontsize',13); ylabel('path orientation [degree]','Fontname','Times New Roman','Fontsize',13); %更改颜色 b1.FaceColor=blue; b1.EdgeColor=blue; 帮我检查一下为什么置信区间和数据反了
时间: 2023-08-14 11:06:25 浏览: 142
slover.zip_人工智能/神经网络/深度学习_Python__人工智能/神经网络/深度学习_Python_
您在添加置信区间时,应该将 `ci` 数组作为误差条的长度,将 `err` 数组作为置信区间的长度,所以需要将两个数组的使用位置反过来,代码修改如下:
```
% 画出bar图
x = categorical({'600','5','1'});
y=[-52.470 -33.936 -24.414];
err=[2.731 2.731 2.827];
ci = 1.96 .* err ./ sqrt(numel(y));
% 计算置信区间
b1=bar(x,y);
hold on;
% 添加置信区间
for i = 1:numel(y)
errorbar(i, y(i), ci(i), 'k', 'linestyle', 'none');
hold on;
rectangle('Position',[i-ci(i)/2,y(i)-err(i)/2,ci(i),err(i)],'LineWidth',1.5,'EdgeColor','k','FaceColor','none');
end
% 添上数据标签
xtips = b1.XEndPoints;
ytips = b1.YEndPoints;
labels = string(b1.YData);
text(xtips,ytips,labels,'HorizontalAlignment','center','VerticalAlignment','bottom')
% 添加坐标轴标签
xlabel('kappa','Fontname','Times New Roman','Fontsize',13);
ylabel('path orientation [degree]','Fontname','Times New Roman','Fontsize',13);
% 更改颜色
blue=[80/255 138/255 178/255];
b1.FaceColor=blue;
b1.EdgeColor=blue;
```
这样的话,误差条就在柱子上方,置信区间在误差条上方,效果应该符合预期了。
阅读全文