(1)画竖直的errorbar
例子:
close all;figure;
h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵
set(h,'BarWidth',0.9);
hold on;
set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色
set(h(2),'facecolor','k')
ngroups = size(volume_month_mean,1);
nbars = size(volume_month_mean,2);
groupwidth =min(0.8, nbars/(nbars+1.5));
hold on;
for i = 1:nbars %--画errorbar
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);
end
for n=1:12
if n<&#61;9
time_lab{n,1}&#61;[&#39;0&#39; num2str(n)];
else
time_lab{n,1}&#61;num2str(n);
end
end
set(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)
ylim([-0.5 2.5])
xlim([0 13])
set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
(2)画水平errorbar
例子&#xff1a;
close all;figure;
h&#61;bar(volume_mean./1e6); %--volume_mean是4*2的矩阵
set(h,&#39;BarWidth&#39;,0.9);
hold on;
set(h(1),&#39;facecolor&#39;,[139 35 35]./255)
set(h(2),&#39;facecolor&#39;,&#39;k&#39;)
ngroups &#61; size(volume_mean,1);
nbars &#61; size(volume_mean,2);
groupwidth &#61;min(0.8, nbars/(nbars&#43;1.5));
hold on;
for i &#61; 1:nbars
x &#61; (1:ngroups) - groupwidth/2 &#43; (2*i-1) * groupwidth / (2*nbars);
errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);
end
view(-90,90)
set(gca,&#39;xdir&#39;,&#39;reverse&#39;,&#39;ydir&#39;,&#39;reverse&#39;,&#39;XTickLabel&#39;,{&#39;Winter&#39;,&#39;Spring&#39;,&#39;Summer&#39;,&#39;Autumn&#39;},&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)
ylim([-0.5 2.5])
set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;)
legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)
转载本文请联系原作者获取授权&#xff0c;同时请注明本文来自叶瑞杰科学网博客。
链接地址&#xff1a;http://blog.sciencenet.cn/blog-2824237-1040575.html
上一篇&#xff1a;【Matlab】如何用plotyy对应坐标绘制多条曲线
下一篇&#xff1a;【物理海洋知识】厄尔尼诺&赤道Kelvin波