matlab画带误差棒的柱状图并标注出平均值

时间:2024-03-22 15:35:30

画带误差棒的柱状图,并标注平均值,matlab代码如下,结果如图
matlab画带误差棒的柱状图并标注出平均值

// code block
clear
close all
load 'plotuse.mat';
avg=[WPE', IF', ISE'];
STD=[WPE_std' IF_std' ISE_std'];
x=[[1:8]' [1:8]' [1:8]'];

h=bar(avg);
ylim([55,100])
set(h,'barwidth',1);
h(1).FaceColor='flat';
h(1).CData=repmat([0 0.8 0.8],8,1);

hold on;
ylim([55,105]);
errorbar(x(:,1)-0.23,avg(:,1),STD(:,1),'linestyle','none','linewidth',1,'color','k');
errorbar(x(:,2),avg(:,2),STD(:,2),'linestyle','none','linewidth',1,'color','k');
errorbar(x(:,3)+0.23,avg(:,3),STD(:,3),'linestyle','none','linewidth',1,'color','k');

str_WPE=num2str(avg(:,1));
str_IF=num2str(avg(:,2));
str_ISE=num2str(avg(:,3));

dim=0.16:0.09:(0.16+7*0.09);
dim_multi_WPE=[dim' repmat([0.65,0.1,0.1],8,1)];
dim=0.18:0.09:(0.18+7*0.09);
dim_multi_IF=[dim', repmat([0.45,0.1,0.1],8,1)];
dim=0.2:0.09:(0.2+7*0.09);
dim_multi_ISE=[dim', repmat([0.15,0.1,0.1],8,1)];
for i=1:8
    annotation('textbox',dim_multi_WPE(i,:),'LineStyle', 'none', 'LineWidth',1,'String',str_WPE(i,:),'fontsize',12);
    annotation('textbox',dim_multi_IF(i,:),'LineStyle','none','LineWidth',1,'String',str_IF(i,:),'fontsize',12);
    a3=annotation('textbox',dim_multi_ISE(i,:),'LineStyle','none','LineWidth',1,'String',str_ISE(i,:));
    a3.FontSize=12;
end

set(gca,'xticklabel',{'4 units','8 units','16 units','32 units','64 units','128 units','256 units','512 units'},'fontsize',12,'fontweight','bold');
legend([h(1),h(2),h(3)],{'WPE', 'IF','ISE'},'location','northwest','NumColumns',3);