(1)画竖直的errorbar
8 g4 m) W/ N9 H5 o例子:5 t0 ]. K0 q& g2 x" E$ H
close all;figure;
/ ^+ z& t* j# z) J4 y! S9 r* C- w h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵! g" f8 G L D* {6 t
set(h,'BarWidth',0.9);& z' ~ n1 ?9 b( }
hold on;) H; j W0 v4 E4 C
set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色- P, X& Y- y1 K2 v! J
set(h(2),'facecolor','k')4 @5 B5 z' s" `( y9 y) @. C
/ G# E, X* R% t @$ K# Q+ g- h
' N$ e" a0 q6 |0 S
ngroups = size(volume_month_mean,1);: F f/ z! w' s& L/ O& M
nbars = size(volume_month_mean,2);
# k, }3 o& Y$ x groupwidth =min(0.8, nbars/(nbars+1.5));2 F: V# I" K- S" o$ n
/ G: v# h4 D0 n' h( F4 F$ O$ ^; `
7 i# X( K6 V5 d: L# D5 o; [ hold on;
% z' n a) f% ?# P0 q for i = 1:nbars %--画errorbar
+ ]" ~+ C, Z' E) D- Z. J x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
. v7 ]9 ~6 c& _3 W# k errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);
( b8 y1 m1 a9 W/ f8 c end
# F& i7 ?* ~2 {, r- M
7 k5 E* Y: @, T( y; { for n=1:12
6 T" N$ o$ H* }; h if n<=97 Z* W* k$ p4 N/ J6 X* }
time_lab{n,1}=[&#39;0&#39; num2str(n)];% k8 o$ B5 B. }% _2 B
else
5 ~7 l' g' m) @( @& V+ K* c time_lab{n,1}=num2str(n);
M" I5 k2 s0 R end% o; m7 p: t* j* A
end0 D# x" G) t/ J' R1 G
set(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)/ @+ @* m ?1 y5 B" V2 B$ @6 t& i
ylim([-0.5 2.5])
- X4 d* M5 H9 s xlim([0 13])
: }. D/ X; q/ Y$ w set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
& L! |( C$ p4 p* w1 @3 |$ V: x
0 |1 e6 E+ U( Y# ~+ A, x
# y/ P T$ f$ _# U) q: D
. d# w) e0 V( X- A" B7 I- R, g(2)画水平errorbar+ a# y3 E; J7 f1 R. _
例子:
/ b' t" b3 Q2 v4 Kclose all;figure;% f4 K2 F( q" O! _: D+ y
h=bar(volume_mean./1e6); %--volume_mean是4*2的矩阵
. t& A9 S' H0 ^ set(h,&#39;BarWidth&#39;,0.9);9 w9 P4 d( o6 W0 |. F
hold on;
' e* \# d- Q7 s& y& x3 N9 B3 a0 C% t set(h(1),&#39;facecolor&#39;,[139 35 35]./255)
! X6 G/ L% c% R0 m set(h(2),&#39;facecolor&#39;,&#39;k&#39;)9 G! I+ D6 `/ W: I
5 d1 m3 o' \+ g; s
3 o/ e( ^5 X0 U2 b- X ngroups = size(volume_mean,1);
2 R B- w1 B r# p; z7 I nbars = size(volume_mean,2);* D' h6 x; p& J8 J+ {
groupwidth =min(0.8, nbars/(nbars+1.5));7 S6 H! o! I: y$ H5 s
7 {- `) K/ {5 W1 d) U. U
- Q% ~# B6 K3 E/ Q hold on;
# D- C3 g( o6 U" `1 |( E for i = 1:nbars- G$ F& B, {, `* |, O
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
0 x2 [- p9 J& R; m* B3 n u6 z errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);
2 K: a4 [4 [& m8 J: H end6 ^7 y( [ P8 ~' ~
2 J2 z; h5 e5 N* t: u7 j! T6 F5 y8 e1 z' n1 s4 v3 {3 C
view(-90,90)
6 i" Z- X S. |# ~0 `/ {) v# { 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)% i) k3 \1 g5 Z" \; i* b. ^) ^
ylim([-0.5 2.5])
8 O3 U2 e p6 V$ D, U set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
9 }# Z* W* |! i9 [9 k% k2 g- {7 r7 Y ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;)# N) {' g/ p$ p) o
legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)& {# R/ }" G7 q# p2 N1 O" V
b; ~; x8 R5 P7 _9 e" X
% N1 \1 J# q( F7 L( j
# b" d b: A+ }5 h/ ]: `
v/ W7 q5 e1 ^% m' _! O3 E% L- x" Q& y+ ^) O$ R. l3 x: @
转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |