JerryYe的个人博客分享 http://blog.sciencenet.cn/u/JerryYe

博文

【MATLAB】如何画带errorbar的直方图

已有 6201 次阅读 2017-3-20 15:58 |个人分类:Matlab|系统分类:科研笔记| MATLAB, 直方图, bar, errorbar

(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<=9

           time_lab{n,1}=['0' num2str(n)];

       else

           time_lab{n,1}=num2str(n);

       end

   end

set(gca,'XTickLabel',time_lab,'fontsize',14,'linewidth',2)

   ylim([-0.5 2.5])

   xlim([0 13])

   set(gca,'ytick',-0.5:0.5:2.5)

 


(2)画水平errorbar

例子:

close all;figure;

   h=bar(volume_mean./1e6);           %--volume_mean是4*2的矩阵

   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));


   hold on;

   for i = 1:nbars

       x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);

       errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);

   end


   view(-90,90)

   set(gca,'xdir','reverse','ydir','reverse','XTickLabel',{'Winter','Spring','Summer','Autumn'},'fontsize',14,'linewidth',2)

   ylim([-0.5 2.5])

   set(gca,'ytick',-0.5:0.5:2.5)

   ye_xylabel(gca,' ','Volume[Sv]')

   legend('A','B','location','NorthEast')

 




https://blog.sciencenet.cn/blog-2824237-1040575.html

上一篇:【Matlab】如何用plotyy对应坐标绘制多条曲线
下一篇:【物理海洋知识】厄尔尼诺&赤道Kelvin波
收藏 IP: 219.146.245.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-16 22:45

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部