(1)画竖直的errorbar
2 L7 j) D: z9 Q# Q例子:
* p7 Z4 ]% B+ Q, o! h7 \6 g# dclose all;figure;
b& [) x* ]! U5 Z h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵
- X* V8 i/ |7 R, q' b set(h,'BarWidth',0.9);0 e: X; Q3 x# P; j( _
hold on;6 `/ A% p9 d i) q9 _
set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色. y- `* C9 z" _* V3 a4 \- U
set(h(2),'facecolor','k')( I& l' a( ?! b
& a2 K3 i' K4 G1 D! I" d- L& e
% V+ z* v7 o# S6 I9 U9 C
ngroups = size(volume_month_mean,1);
3 `" C3 K: o/ f: p* b C nbars = size(volume_month_mean,2);
( u- K& a4 M/ ]% c6 x( S$ m% h groupwidth =min(0.8, nbars/(nbars+1.5));+ g/ C5 W1 ]/ j8 m5 t N6 `
. _% _* {6 B8 F4 Z7 {+ f) q3 r7 a
4 c! \- x7 F5 R9 z; Q hold on;
3 ~' s7 K" l5 }/ t. ^- w+ R3 N* Z for i = 1:nbars %--画errorbar
# e1 V. p$ u" }, i+ ^+ X4 H x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
% M1 v6 `- }/ ?0 ]# g errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);# j6 p6 v' R+ j9 _& p) r' u
end
3 C/ ~3 L) ~' R1 W' A0 Q- t
. F/ b# K1 Z" l* ^6 Z' i* k for n=1:12$ E, T& b5 w2 y3 y/ T
if n<=9 x b) [. T. q) Z% A5 C
time_lab{n,1}=[&#39;0&#39; num2str(n)];5 C: B% l" c! w
else
$ }6 |+ f/ ~* V# c time_lab{n,1}=num2str(n);+ V( o/ ?. A: f$ h! u! C# Y
end
0 j6 S% m5 d) x1 I end
9 M: y2 {: L1 V4 qset(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)
" I. j; w; G2 v! f ylim([-0.5 2.5])8 {5 I2 G+ f1 |
xlim([0 13])$ p# Q) w7 J- }6 A3 o$ V
set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
" u8 @! Y" L. x" s% T4 e: y
' E3 r7 t& V! C8 v% Y8 V9 b0 ]- r" k! w R
! {1 }4 P* e' x; i( ^4 e* Z. |(2)画水平errorbar
: K: U. s, e, m+ b& N# Y& f) Z% J例子:
+ P! Z2 m* q9 q# n9 cclose all;figure;6 Y0 {- @1 W0 T, o; y
h=bar(volume_mean./1e6); %--volume_mean是4*2的矩阵
, v" e; u$ O' b) v. s$ e+ N set(h,&#39;BarWidth&#39;,0.9);
6 Z& Y# ?3 E, z# \5 x hold on;$ a, R+ ^+ P! q" J4 [% S
set(h(1),&#39;facecolor&#39;,[139 35 35]./255)" j3 d, v! ~3 L# ~8 `5 ~* b
set(h(2),&#39;facecolor&#39;,&#39;k&#39;)5 E: C8 j3 O0 `9 D& N; x$ R
" x4 S. K: j! \& I2 a6 D+ j5 B/ T Z u4 W W% U; ], C. o v0 F
ngroups = size(volume_mean,1);4 I& _9 Y( n+ o
nbars = size(volume_mean,2);
& Q- }" Q9 m3 M groupwidth =min(0.8, nbars/(nbars+1.5));0 H0 p4 y- z$ C$ T
0 B2 j3 r3 Y, {4 H0 C! F4 Z* d
$ k# `2 _% u$ T+ U( V0 m hold on;$ i$ s6 f! e Z$ R' A
for i = 1:nbars
: u6 D7 R" M" B: t* t, Q" e; S5 h; n x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
3 p0 y0 c# n7 V. T6 j9 a errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);
2 y9 R/ R/ ?( T6 M. S end5 D% l7 p7 q* W; u- i8 R
6 p% u) Q* ?( ]1 h. \; I
N* i5 a: w/ h w
view(-90,90)% _3 I4 a" k% r
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)1 i8 m3 X* A/ c* f- D; r( m
ylim([-0.5 2.5])8 K T& c2 V! m* K& W: e
set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)' E/ p' T ?- a! }/ F* z$ v
ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;)" _0 ^5 u: f; Z
legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)
! N3 s+ o& W( j' N$ t
. J7 d, i4 {# Q9 q
. }' \+ l7 \( F% y g% t
# A4 t7 R z* ?+ O+ @9 S
+ |* ]4 C# c' B o' u+ o' a; Q( T( L1 T1 e; E' x. I- o0 t! K
转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |