(1)画竖直的errorbar
% _# ~5 F" @9 a4 M+ {# j) v例子:
; q7 q1 T1 T/ N4 y# W: K9 a/ o' ^close all;figure;
$ x% S8 K) Z' Z h=bar(volume_month_mean./1e6); %--volume_month_mean 为12×2的矩阵
5 r" @$ v& [: v& ~+ [6 B9 Z* \/ E* I set(h,'BarWidth',0.9);
# ?7 s! w) t: Q2 C0 N$ {8 ]" R hold on;
' c5 S% J& g2 U set(h(1),'facecolor',[139 35 35]./255) %--设置bar的颜色
! h0 W* v, W& b: t set(h(2),'facecolor','k')
% o0 e( n/ D H. M; F" [7 o7 M7 g' R2 |! O* V
1 i |7 _4 T( q
ngroups = size(volume_month_mean,1);; E# `' s& r7 W! _
nbars = size(volume_month_mean,2);
. f2 F8 {! W" t1 f- F: o groupwidth =min(0.8, nbars/(nbars+1.5));- r0 Y% {# D8 M3 K
' D9 U% J9 {' A( P* R! c. B
m3 n4 q1 |& F. J4 b2 I! c. T hold on;
" I" a8 f( B1 P# G) ^5 m( S for i = 1:nbars %--画errorbar" R# u* C& W+ m8 _
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
7 }% T6 W$ _7 v7 e" S+ g: H" p errorbar(x,volume_month_mean(:,i)/1e6,volume_month_std(:,i)/1e6,'o','color',[.5 .5 .5],'linewidth',2);
3 Z6 H. Q; U9 ?) t# _! F end5 n) C- e* u. [! @
0 v9 ?- Z" N5 B( z& v for n=1:12
9 e0 a% M+ c6 A" J2 f' j if n<=9
/ L- L! j. A/ y; ^0 x time_lab{n,1}=[&#39;0&#39; num2str(n)];
U" y2 W; T0 Y5 A& v6 A else
, }7 G, M6 y5 B9 I. Q time_lab{n,1}=num2str(n);
! w# G5 D: S) Z; ^: i& |$ p! H end
8 R, K7 H' U8 m# L end1 R7 G& j R+ I2 D
set(gca,&#39;XTickLabel&#39;,time_lab,&#39;fontsize&#39;,14,&#39;linewidth&#39;,2)
5 s9 l0 `9 M T" [. z8 b ylim([-0.5 2.5])
. Q; |3 j9 c$ }8 ~! S1 F xlim([0 13])
5 w0 W t6 k$ k0 z0 N* A set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
" ]" [5 F7 X' h 6 l. w0 f4 _2 x9 ?+ k
" T i% f1 t }7 d3 E
# g9 N! L; s. ^' A
(2)画水平errorbar5 `. k9 [2 a* K: |& H
例子:8 ~+ u" G) G6 a6 q
close all;figure;
) y7 F; A5 I, H) y+ d3 e( ^ h=bar(volume_mean./1e6); %--volume_mean是4*2的矩阵
0 H# c! O; t, D7 [ set(h,&#39;BarWidth&#39;,0.9);
( K$ g4 K: H( E1 k6 h. d hold on;
5 F6 D$ B" H; X+ H' x set(h(1),&#39;facecolor&#39;,[139 35 35]./255)
& O3 n1 o: d& N0 ]/ i set(h(2),&#39;facecolor&#39;,&#39;k&#39;)) y' o/ `. S; t3 i `
/ v7 a6 _' I( y+ {
* G, ?/ I/ B7 D
ngroups = size(volume_mean,1);
" y3 N/ k# x( @# p nbars = size(volume_mean,2);" i# Z: {( d+ `' N* z _
groupwidth =min(0.8, nbars/(nbars+1.5));9 J0 Z" H, [" w0 R5 H) k9 e
" h' W! k& p. e5 d& h; y: t( M6 C- j1 t6 K2 _
hold on;
6 ?# P( J* @( y( }% ]3 }2 w+ F9 k for i = 1:nbars4 g5 E9 j" d0 E5 A& L" x( I
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
9 Z7 \! b' t5 q( T0 x; p errorbar(x,volume_mean(:,i)/1e6,volume_std(:,i)/1e6,&#39;o&#39;,&#39;color&#39;,[.5 .5 .5],&#39;linewidth&#39;,2);% X0 t; M" Q0 ]9 m: i
end% F, I$ _, Q; Q0 [9 K3 r* w# K
! l8 @* W% r5 G7 D
" j7 n# v' L, z view(-90,90)9 @ O% m/ }) v$ f; 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)
: l9 D1 U) F# D. c' {4 Z4 r! V, i! T ylim([-0.5 2.5])+ `- R3 ]: P+ L9 R8 a4 X/ I
set(gca,&#39;ytick&#39;,-0.5:0.5:2.5)
9 ~1 S5 y, g' k8 D ye_xylabel(gca,&#39; &#39;,&#39;Volume[Sv]&#39;)/ R: u v" N: v( c& l. E" x; G
legend(&#39;A&#39;,&#39;B&#39;,&#39;location&#39;,&#39;NorthEast&#39;)8 ]4 Y" [$ @, e6 V& B! t6 R( c( x
% t, K1 }% x) e: h) X
$ J* d4 T# T# K7 D5 W7 [3 ]! |! R9 [" F; _8 r- ^9 K1 I7 f
( p5 v/ Z5 Z+ }! U# `
- y! ~& L7 M- k9 R) R
转载本文请联系原作者获取授权,同时请注明本文来自叶瑞杰科学网博客。 |