(1)画竖直的errorbar
; v( w, p5 P; D/ u: m# Q U例子:
/ I* _3 L6 F0 {& b7 n1 pclose all;figure;
) S9 k- w! ?+ N h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵. g& q/ n' l/ T+ J; t9 y$ L
set(h,'BarWidth',0.9);# Y) D$ B5 F; ^& F
hold on;' e0 a5 d6 p9 f
set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色3 h) O7 B/ M# m; T6 N) F( [
set(h(2),'facecolor','k')' s" y8 g& p# @* J
: m1 f! l) n. a7 _# t# J5 D% A: U
# y# r/ \0 ]/ ~" z1 |6 L! {% q ngroups = size(volume_month_mean,1);
; i4 m0 Z3 h, l* X' x+ w9 w nbars = size(volume_month_mean,2);0 p @$ ?) f6 I
groupwidth =min(0.8, nbars/(nbars+1.5));0 P: m1 D2 E0 v h( j4 |3 @" L
6 Z# ^8 I- M, D9 B5 }4 M% d. V6 [" q: N
8 b1 G4 C* H, c, }, O hold on;) t6 A' I, \! C% A, r$ }+ x: ^
for i = 1:nbars %--画errorbar
. [% u5 ~) o( m x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);6 e' {! i3 A3 E0 {* P/ b, R2 k7 [
errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);0 }$ k: Y8 I* @ Z5 p7 z$ P
end
! ]7 W' U8 e7 a! b9 W
9 U8 Q1 ~" e, q- } for n=1:12
2 V0 c8 q5 G+ `3 ^7 }5 H6 a( @ if n<=9- p2 f. E* y+ `; Y
time_lab{n,1}=[&#39;0&#39; num2str(n)];
' F/ s4 M$ V# w else
) d* J& L2 c- x$ j7 D9 v* Y time_lab{n,1}=num2str(n);
" Y( i6 O! Y8 h1 Z9 Y; q5 R end# D) g( J5 g! J4 Y7 g! U( t3 R
end$ A1 _+ M! E+ H
set(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)! C6 c# B9 G( D* J4 `
ylim([-0.5 2.5])6 I% K- P( Q( F b: k/ t. d
xlim([0 13])5 e5 w* j( z) w* a/ @3 @
set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)+ q" Y( Q4 r, T C( w: W7 @
7 J: o% a% ~# H
5 |) N: A/ P, _5 @" V# L
' E' h# _; f9 J3 {(2)画水平errorbar' k) [* w0 a, U' `6 p" r: H- b' n9 `
例子:. K6 N% C& p( J/ R" f' e
close all;figure;2 w' ^: `* c, j( q& c. M
h=bar(volume_mean./1e6); %--volume_mean是4*2的矩阵
* n4 o& g* g; P0 _5 r) Y% J+ ? set(h,&#39;BarWidth&#39;,0.9);
( W# h& c9 g, b8 |# x! J4 } hold on;
3 A; `8 h: z/ R1 X set(h(1),&#39;facecolor&#39;,[139 35 35]./255)1 c- J% w- e5 k% G7 W, d
set(h(2),&#39;facecolor&#39;,&#39;k&#39;)
* a6 M# e( X1 ?3 @, ^$ D8 ^* v
, l; u2 K3 @: e. d' K$ ^4 l: U6 b) P7 Q3 j
ngroups = size(volume_mean,1);
8 i1 _! X0 n1 G4 Y- s% ? a4 B+ I nbars = size(volume_mean,2);
/ W8 v- z4 M" g: @ groupwidth =min(0.8, nbars/(nbars+1.5));
s2 v4 |% b8 K: N$ a* c. e# h$ `, H4 m' R5 K3 p0 W) h
3 l* S2 ?: C6 W7 s9 \& h$ V
hold on;
, s! h6 P$ F- E9 i4 x3 k8 |6 g) q for i = 1:nbars: s; R% N& u* |. Q& f0 ]
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);0 X" z) v( ?7 g9 q
errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);
+ I* a( o( @) C$ `5 t end7 a) r; a- `8 o' m9 ^
7 b% _7 G l& N8 ?! f2 [6 Z
1 J0 `* F2 c; t/ f( V
view(-90,90)
) a; y e# g/ [2 y1 e 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)8 H( c9 w& }/ G, x. u
ylim([-0.5 2.5])
- i6 O/ U; s8 t' C) c5 S" N4 o set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
/ x, y$ \& G7 l ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;)3 c4 ^" Y' ?) v5 @7 k4 B
legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)
# K: P; U. } P( k- s 2 `* f- v* r, p0 Z; g
$ V, O" k9 m7 m |2 c. v
: F6 {6 u; K" j( Q2 F/ e, B% n: D( L , l7 b0 v) Z4 X5 u
+ C: x t5 H1 b, a
转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |