(1)画竖直的errorbar/ Z3 S. ^4 d' b9 I
例子:' r! n' [7 F9 G6 V1 `
close all;figure;
, [* H! @/ ?6 ?4 d h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵
3 ~! C. j4 d! G1 ^# T- ? set(h,'BarWidth',0.9);6 K* n6 L8 m/ n3 A2 I. [; J- U
hold on;. u7 t" C: _. e3 W! ~+ c
set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色2 V9 M" l4 V# S
set(h(2),'facecolor','k')( H9 A' r8 m9 d' t
; p( U- q. v) O9 N
, b @2 l- y: U. N- ]1 P; m
ngroups = size(volume_month_mean,1);3 x) ^' i+ Q4 [, M4 ?2 B
nbars = size(volume_month_mean,2);
$ b3 }7 v, p* W9 X0 r5 ]0 v groupwidth =min(0.8, nbars/(nbars+1.5));
* C4 |$ ], s. N: \( E/ |$ U# b' M0 g
6 e c9 O( G2 Y" p) `1 w2 Q* @ hold on;
# W5 \9 J/ L8 | C; F- ^4 q' A for i = 1:nbars %--画errorbar
) Z+ L, v6 [$ U/ |, c7 L1 c3 P x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
/ G% q* o( G( k errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);1 b% N3 A$ F5 V/ v5 `6 d7 x2 @
end+ f% N) k u: S9 I
4 q. y, V9 b7 S2 @0 m for n=1:12( {2 T7 k* m6 @; F! f; x0 F
if n<=9/ U' V' M$ I. _9 s( _) g, d/ T- l
time_lab{n,1}=[&#39;0&#39; num2str(n)];
' a! }( U: W4 W0 P: v8 S+ d: M else
2 H: N% T0 n7 Y/ [ time_lab{n,1}=num2str(n);
& }$ v0 ~+ ?( g! A/ N* v8 |3 c end
! M. n9 q: N' V end
2 @0 L, G6 \1 m2 W F( Jset(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)
& m% r$ m# y* l1 v ylim([-0.5 2.5])( A: \4 q9 U9 n4 J; Z
xlim([0 13])
, ~' t' z6 g/ u; ?' @1 {3 D set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
- n1 b0 L Q+ B4 W8 ^* s) X. S# j 4 T& V9 S* V' X; e+ }; ^& N
; \5 S, S( R9 B9 E8 O+ b' b, N. \( X
(2)画水平errorbar
+ i0 ?( |8 y3 a) F$ t例子:3 ^6 h R5 w- u7 {1 c
close all;figure;
) Z' z' w; x, j6 o h=bar(volume_mean./1e6); %--volume_mean是4*2的矩阵. \) r9 a3 H( s
set(h,&#39;BarWidth&#39;,0.9);
; ?9 M4 {! m( k' i4 {, V hold on;- _, U- G: A+ M9 w
set(h(1),&#39;facecolor&#39;,[139 35 35]./255)
; w7 k: j8 R0 m1 Z set(h(2),&#39;facecolor&#39;,&#39;k&#39;)
7 \4 q7 R. ~' q7 D( n5 a% g% T( R7 e& p
7 v$ I5 n0 O' g" r ngroups = size(volume_mean,1);) J" ]- P- W. {( i t
nbars = size(volume_mean,2);
( P- N8 i6 i5 P( `6 P groupwidth =min(0.8, nbars/(nbars+1.5));
' ^$ @6 o6 m% ]2 T. R3 p6 b- C# F% u
7 g% W/ X* g( ?1 N& D% ]+ v' g1 o( z hold on;6 D: E! y$ G3 Z' }0 b5 Y7 Z, s
for i = 1:nbars
7 s1 e' R8 K* d) N x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);" g: i; B. y5 K
errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);' n K# ^* u* b& B7 Z5 G9 }
end) F( E$ a' H; r: F, v# j
, a2 @. Q7 j& k8 {# G1 ?+ }6 w( ]) c5 T( |; H5 G
view(-90,90)
K' E# o1 j0 ?. H 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)
$ v6 u* N. J- y' ?. `1 x ylim([-0.5 2.5])
2 Z% o; A" x7 S2 `5 d- z" T set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)3 K u9 V! ~5 M. Z& A
ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;)5 C0 l$ c$ ?5 Q p. ?" |
legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)
3 F9 c) m( Y( r1 M3 C& e, e# v! v7 F " F) ^7 r W0 ^7 w+ l1 k
( K5 y0 q( c4 @' `) C. N
& V; t+ D. u) h/ `! ~! V. ~ ( B K' I ~! P( d ^/ O
9 } G* g( o) w 转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |