在数据统计分析时,往往会用到多个数据分组进行比较,这里介绍一种数据可视化方法。
实例:
% 数据
volume_mean=[0.73,0.45;
0.42,0.43;
0.70,0.42];
volume_std=[0.65,0.17;
0.35,0.14;
0.44,0.13];
%绘图
close all;figure;
h=bar(volume_mean);
set(h,'BarWidth',0.9); % 柱状图的粗细
hold on;
set(h(1),'facecolor',[139 35 35]./255) % 第一列数据视图颜色
set(h(2),'facecolor','k') % 第二列数据视图颜色
ngroups = size(volume_mean,1);
nbars = size(volume_mean,2);
groupwidth =min(0.8, nbars/(nbars+1.5));
% errorbar如果用不同颜色,可以利用colormap的颜色进行循环标记,这个例子没有用到colormap
%colormap(flipud([0 100/255 0; 220/255 20/255 60/255; 1 215/255 0; 0 0 1])); % blue / red
% color=[0 100/255 0; 220/255 20/255 60/255; 1 215/255 0; 0 0 1];
hold on;
for i = 1:nbars
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
errorbar(x,volume_mean(:,i),volume_std(:,i),'o','color',[.5 .5 .5],'linewidth',2);
end
set(gca,'XTickLabel',{'2014','2015','2016'},'fontsize',14,'linewidth',2)
ylim([0 1.5])
set(gca,'ytick',0:0.5:1.5)
xylabel(gca,' ','Volume[Sv]')
legend('data1','data2','location','NorthEast')
以上实例可以参考使用。
errorbar的局部调整:
1.头部宽度调整
% Create errorbar
X = 0:pi/10:pi;
Y = sin(X) + 1;
E = std(Y) * ones(size(X));
ha = errorbar(X, Y, E);
% Width of the top and bottom lines of errorbar
xlength = 0.2;
% Make horizontal lines with 'line'
for k = 1:length(X)
x = [X(k) - xlength, X(k) + xlength];
y_h = [Y(k) + E(k), Y(k) + E(k)];
line(x, y_h);
y_b = [Y(k) - E(k), Y(k) - E(k)];
line(x, y_b);
end
转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。
收藏
分享
分享到: