(1)画竖直的errorbar& o4 c/ J, ~& h* |
例子:
/ s' i1 D' i' U* Z6 x* Y* _close all;figure;) l, V$ a3 P, I8 U; B$ U( X
h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵, L J% A/ l7 I6 R0 X! |
set(h,'BarWidth',0.9);
3 r$ y, N$ ?$ `+ `$ o hold on;4 J. H, E0 ?* Q. I9 F
set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色
% l# q: @: x% G; G3 f set(h(2),'facecolor','k')* N/ y: w6 r6 A" m
1 N6 B5 U4 u" o3 ~3 R7 D& H
" e9 S% R+ e/ n+ m ngroups = size(volume_month_mean,1);8 y/ f) J( w/ Y: B7 N' D
nbars = size(volume_month_mean,2);
- m1 J8 q* b7 P' }& `: g& O9 T groupwidth =min(0.8, nbars/(nbars+1.5));- U& I# Z% |) z1 O; E
- N: A% M$ O/ V" K7 D. T0 i
j9 y, N0 Y% F* m, e
hold on;8 J& U+ x" P9 d$ e3 T9 T% w
for i = 1:nbars %--画errorbar# }( C" o* [, a
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
( Z' X3 R3 a, m6 [9 N! Z errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);5 i V$ ~ L. V8 s
end/ Z) K+ X0 s& c5 ?7 E
& ^$ m( B6 _5 x9 Q8 K
for n=1:126 E) q8 `. a4 [9 z* ~
if n<=9
* M7 W$ j% e% \) R" W9 z time_lab{n,1}=[&#39;0&#39; num2str(n)];
( U# r4 ]! v: [" X$ l, s* i else! b n) j" E8 Q$ z& v, z
time_lab{n,1}=num2str(n);3 c& \6 h) n3 y- W7 k+ @: t; x
end) l6 W* X1 Y W6 m
end9 ?& h* R) r l! ?3 \5 g: t" p
set(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)2 B4 ?! n5 i2 Z8 v/ M8 S
ylim([-0.5 2.5])
4 @: e3 d5 i8 m xlim([0 13])
" G, v* I, C4 n6 t9 ` set(gca,&#39;ytick&#39;,-0.5:0.5:2.5), U4 b( {( q+ {
# _- }( J+ z7 [+ k
! C% ~: }+ a- h
1 F) q4 r# ], d) i' K(2)画水平errorbar5 U( A$ f+ ]! x. l0 p) P# x: C& t
例子:
9 Y4 L/ ~8 I$ sclose all;figure;
! O* l4 Y- w& q6 p# C% w& p' ^0 ^ h=bar(volume_mean./1e6); %--volume_mean是4*2的矩阵9 u6 c: w/ t! Q6 Z, J
set(h,&#39;BarWidth&#39;,0.9);
# k0 R+ F7 c. I" r. O N hold on;, x% ~ T# v* w6 h. ^) S$ h5 _* u
set(h(1),&#39;facecolor&#39;,[139 35 35]./255)
# T& ]+ ?- [' D; c" J% P( v set(h(2),&#39;facecolor&#39;,&#39;k&#39;)
' w7 G& p, m# g/ v b; S+ h& U4 X( r+ ^ |/ ^
7 H: I5 X5 m5 R
ngroups = size(volume_mean,1);
# l1 k( `+ ]7 G# X% ?6 k3 c nbars = size(volume_mean,2);
+ u# T7 t# e! \ groupwidth =min(0.8, nbars/(nbars+1.5));& `- W! U* S- Q& t+ m! ^4 {
8 Z$ x8 f0 @/ T5 W
+ J& f8 z2 A, E7 g7 @4 t& o% n
hold on;3 w! w, Y! I, r- n0 g( |* k" H
for i = 1:nbars
- L8 R1 M+ M, r( [, O& s* x x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
3 ~7 m e0 N) ?# j% K6 S$ F errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);* g$ y. K# b, d1 Z3 ^+ Z
end* u. u% P6 P" u! k- S2 p, t
, a( H3 x$ n) i4 }
( D: I, c5 H9 Q5 |# ] view(-90,90)$ d+ O) _" ]" s# u9 i
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 N! ]8 g9 _, r. X/ ~2 @* q* ~ ylim([-0.5 2.5])
5 K6 t( m+ |( I. P# l1 j set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)8 Z5 |+ l7 X- e6 e- h/ h
ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;)
4 @% Z/ T; v% q5 l legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)
, E$ B3 D3 {5 R& n4 h# h& F- S4 W
' t$ G$ t& H: }6 m1 `; D4 A' [, d7 j S! Q5 W+ [* t
) C ] i# ?, T3 I1 E, {; L- b
* `5 ~7 T+ I! R g
1 H E6 c6 r, E; c 转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |