matlab errorbar 例子,科学网-【MATLAB】一组含几个bar的柱状图的绘制以及errorbar的添加-叶瑞杰的博文...

在数据统计分析时,往往会用到多个数据分组进行比较,这里介绍一种数据可视化方法。

实例:

% 数据

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

转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。

收藏

分享

分享到:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值