(1)画竖直的errorbar z% l% P* V" B
例子:' u/ ~+ N$ R& W
close all;figure;
2 B I! O+ O1 F6 e+ c; k* E9 R1 p h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵7 K. B( u4 D1 a! N A
set(h,'BarWidth',0.9);
2 a) |. h* w8 _% v hold on;* r, _0 I7 J8 q% r$ l
set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色
7 J* v9 K# j u; R set(h(2),'facecolor','k')8 K) g: ^/ p* W8 L4 y
" r1 N( v* {( B3 c$ C$ {& q& a h, [' `: S4 Q8 f' O
ngroups = size(volume_month_mean,1);" {# t7 ]; F% E4 b7 \- `. h a# y
nbars = size(volume_month_mean,2);3 I3 v9 W+ u# V6 k$ Q- | h
groupwidth =min(0.8, nbars/(nbars+1.5));
+ p8 {7 r: b& L/ x5 B4 B9 A$ s5 I9 L" L
- }1 |' x6 o8 p5 o/ I
hold on;
& M) H- B4 T: L for i = 1:nbars %--画errorbar
) r4 c3 B; s6 ]) ]' W2 ~ x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);, w7 R, k3 Y- A$ \6 H( S& U8 F2 e1 o
errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);
* @# q" L! m3 F+ M6 |% a end
( `2 ^& ?% u2 T) r& E1 \ O8 a' F" e
$ t( F2 J. ~2 B for n=1:122 G9 V% d& A/ W
if n<=9
$ v. j6 j: t* x1 k, D- g time_lab{n,1}=[&#39;0&#39; num2str(n)];
: w, a; J8 v6 l" \2 r8 c) B else
" P8 v1 k& Z3 D+ f time_lab{n,1}=num2str(n);
. E/ p; M! j! S: h0 W- O$ A end( I T F7 B8 G- ?; c# m, j& ^
end
% t6 J( o5 `% zset(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)
3 Q+ a9 ~- M4 @- {! N8 f ylim([-0.5 2.5])$ Y) B* X J2 ]3 t/ l& m' Z+ m
xlim([0 13])
! R1 f& K- F H4 f set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
) }5 v3 ~2 I9 v8 J" Q3 T. s0 Y 1 O/ S% z( t4 @6 W) P# O% }& Q l
: X& {8 j; M( x* z, r
% |9 X# ~* h3 }/ e: B(2)画水平errorbar
% n1 w5 U8 p# s3 J2 B* z1 x例子:3 z6 h% _9 `' p$ H) h
close all;figure;* `7 S* j/ m4 V! `& Z4 B
h=bar(volume_mean./1e6); %--volume_mean是4*2的矩阵
5 `0 c" S6 N8 @7 m h% N set(h,&#39;BarWidth&#39;,0.9);: e( \5 W; o* d2 X. j+ d
hold on;$ h7 e0 {& U. t1 X
set(h(1),&#39;facecolor&#39;,[139 35 35]./255)1 v" F! A( R, ]; K) h
set(h(2),&#39;facecolor&#39;,&#39;k&#39;)/ |7 g, @. M) V
& s6 p4 }$ m5 Q
5 p o; s3 l( K+ [ ngroups = size(volume_mean,1);
- x7 Y, q- H' | Q8 O" x% Y W nbars = size(volume_mean,2); G6 |+ A4 S- z% Y% f+ c
groupwidth =min(0.8, nbars/(nbars+1.5));
" G/ Y- n. b) ~* T
# t1 g- Q, v6 |. B# U1 V
- l& u' W7 z8 d2 x; y hold on;4 W3 [* i6 B+ O8 M- G9 W3 J$ j: C2 e
for i = 1:nbars3 E: |5 o8 K% M5 s# k% R+ h8 f4 k
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
: L8 p7 p' K5 }- A errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);
* ?+ [- T% o( t; @- R end
% h+ o; h, u0 @( v1 m6 B' S) w0 @7 r5 H: h. n4 E
" N0 t* {% y( ?6 d view(-90,90)' B; k1 K9 @' q' S- F0 ?2 q
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)
3 ]( b6 j: @5 p$ q$ ?( l ylim([-0.5 2.5])4 ~2 I0 I: m& d) h L. P
set(gca,&#39;ytick&#39;,-0.5:0.5:2.5) G( d9 L9 D3 `* a
ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;)( P+ d) C. M- z8 T
legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)' P3 h$ A. w: u- e5 h( h( B
- D9 \% G. l% N- O7 t' }- D& A$ i- {
7 [4 W4 i) |4 L
4 }9 N7 R5 D/ Z5 @4 ?, M/ {5 Q
# [" m$ W$ _! L8 D. V, V
$ c1 r# x6 I' \/ Q' a6 ]1 D 转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |