(1)画竖直的errorbar
* r1 n. ^5 ^: I o6 \8 ^' G例子:
3 q) z- U: w9 t: i' l6 f' m6 ]close all;figure;8 m8 @% o& u; M0 l9 ~: o
h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵; b' [) P% U0 G( l& |
set(h,'BarWidth',0.9);7 c T8 S* ?- G5 w" \$ O
hold on;
2 ~. n0 e3 o2 x* \# O set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色
- C x& f2 U& h* Y# N- L6 b* B9 y set(h(2),'facecolor','k')
7 Y& A9 V, _' r* a( C
/ y) F7 n4 @2 M }2 N
% u; l3 C& H' {* @: _ ngroups = size(volume_month_mean,1);
% }2 M7 n( a( W/ @* B | nbars = size(volume_month_mean,2);
: g7 q4 d9 C6 W) Q0 J4 X, W5 ~ groupwidth =min(0.8, nbars/(nbars+1.5));
7 M* A; d, N! _- F: K1 l
& ^, |0 \. K* C# r5 m' E0 `5 A5 N! i) `2 ]) H
hold on;
' J7 z( y; [5 m: y6 |( I for i = 1:nbars %--画errorbar# z" |* [ U7 {# |7 {/ u
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);) D( k- x' u2 |: m4 }6 q G
errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);0 y; X3 M3 O9 L `$ }
end
9 `' }3 h) u# F! `% K
" r) K6 ~! z: g( X& t) F1 o- v" c for n=1:12/ Z" o6 c7 Q/ O8 o5 k
if n<=9
# a- M+ J$ V3 ^* T3 { time_lab{n,1}=[&#39;0&#39; num2str(n)];/ N7 P/ d, D q
else2 E. J/ E/ X2 V0 A! q' ~3 \
time_lab{n,1}=num2str(n);* u$ _) X3 b* g; n
end5 k; s2 m- q& f6 h3 A5 A
end
7 _# ^! [ c. I g0 Bset(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)
6 {/ S2 L* [7 Q# q, L; S! w. s! h# ? ylim([-0.5 2.5])2 J: i8 p8 o" ~' V7 D
xlim([0 13])
5 M! E# ]2 n1 A5 Z4 x m set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)" K' B+ K! Y) X& j5 E9 x6 m- Y2 {/ d1 j
3 I9 z: w1 _& {; h4 @; T+ ?
/ j' d0 W+ S6 R I. t! C- L/ m" C9 g: @1 r. `) T% q
(2)画水平errorbar
8 `/ M# J: S8 S5 |5 _例子:
3 x. w. o" Z: ^) a& bclose all;figure;$ z; W( ^' p D/ s8 e3 q6 O \
h=bar(volume_mean./1e6); %--volume_mean是4*2的矩阵
( t' d8 h6 `6 j4 |- O& B+ H set(h,&#39;BarWidth&#39;,0.9);
' n0 n& w4 }& x+ f# K7 Q) N hold on;# U- Q) X2 I- ]9 K5 j2 S. N! C0 o* r
set(h(1),&#39;facecolor&#39;,[139 35 35]./255)7 v2 O* |& r/ w# w0 y- t; f C7 L
set(h(2),&#39;facecolor&#39;,&#39;k&#39;)
( l0 M$ n! _$ O# g& E: t6 }3 L
Y) e( v! R$ B' W9 o2 X/ O; N8 p4 F N H5 i/ B/ G. [6 g7 z
ngroups = size(volume_mean,1);
0 G9 _: s. C5 C; Q o: S6 C nbars = size(volume_mean,2);( \8 `5 v7 a) W3 p! e
groupwidth =min(0.8, nbars/(nbars+1.5));' y2 Y& C. f. b4 ?4 D# Y
- |, F/ b4 m4 L
& v0 f2 g9 ^, ~# E
hold on;9 `$ k0 ?% \( d, G; H5 I' k
for i = 1:nbars
! S* f# l" B) Y6 G9 m7 m( s x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
3 b( f4 r2 V' O* S j! n errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);
( w: ^' |' S7 w* W$ l end' m# w; l4 q/ u
( r( w0 C$ w# t' {8 G, X
0 I' y' c/ _9 k view(-90,90)
; q2 E ~: ~0 F0 l) D 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)
9 g# w. j9 x2 S0 P& W8 W ylim([-0.5 2.5])
7 K! h+ r y! B set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
: p* ?. R5 M4 A9 _ ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;) f3 } s& u: I$ G
legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)+ t9 C5 ^ {7 q* r9 l
/ a7 P9 ?3 @9 }0 K
: h0 U4 A( z3 O; P* y- _7 O' T) O6 S3 d# W
+ A* r9 N$ w; V# W1 h
0 }% z. t, T/ z, T
转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |