|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 Zedd 于 2020-3-18 10:10 编辑
% z2 [4 B' p( [+ G
$ m) ] e/ n& [. D0 [画风玫瑰图,网上查找到的风向与风速强度都有点问题,修改代码后,与大家分享,有什么问题可以讨论。- a2 S5 K' Y1 _
function varargout = wind_rose(D,F,varargin)
, p5 g; x3 k& e$ o/ t/ [%WIND ROSE Wind rose of direction and intensity, p; r3 J/ T) S5 W6 r- h
% * X1 h2 m( e! G) B s% l
% Syntax:! S$ y/ G: m9 e
% HANDLES = WIND_ROSE(D,I,VARARGIN)) x; U4 N/ k% _ p: z4 ]- ~! N
%
7 d% k5 Q) j0 D! p& U" u4 P" `: A( x% Inputs:# L/ y5 t( q, H2 b
% D Directions
2 L& O7 p) `. g' n/ ~% I Intensities$ `( U& J, e+ g& f j1 r* ?
% VARARGIN:
% ?- `8 t) w& S( A7 t* Y) \% -dtype, type of input directions D, standard or meteo,2 _8 J; D- e* m8 n. O3 ~
% if meteo, the conversion dnew=mod(-90-D,360) is done;4 B' { l& X: i2 D5 a$ I3 @
% if not meteo, standard is used (default)
( L4 t5 m6 ~3 ^0 w8 h6 T7 v0 ^% -n, number of D subdivisons
* y2 v- l0 v9 `# }4 l% -di, intensities subdivisons, default is automatic1 M' ~+ F: z% O' `
% -ci, percentage circles to draw, default is automatic
) l( c f Y% l/ }, y% -labtitle, main title$ w4 m* a; T; J; i2 n0 M' j1 ?
% -lablegend, legend title
3 u8 a& w/ L; i, q% a% -cmap, colormap [jet]
9 T7 k6 ^; V7 S8 t3 p; X% -colors, to use instead of colormap, for each di6 y+ d% p6 K- b9 S
% -quad, Quadrant to show percentages [1]+ A3 z$ R1 |) v/ l9 v& S) `7 t
% -ri, empty internal radius, relative to size of higher; k/ c# a- y+ s- @7 f4 _# d
% percentage [1/30]4 E- K) @9 u) y: N J0 J
% -legtype, legend type: 1, continuous, 2, separated boxes [2]8 W" a# n- t; a; ^0 u
% -bcolor, full rectangle border color ['none']! B1 T* ^, i4 F+ R' A% n2 \1 K* `
% -lcolor, line colors for axes and circles ['k']
4 X' u. d5 o. a# z8 q1 R+ F% -percbg, percentage labels bg ['w']
' b. ~, g' ?1 z' s9 l) R9 f2 R% -ax, to place wind rose on pervious axes, the input for ax
6 I5 T" \5 v9 D/ ^9 c' x8 l4 b H% must be [theax x y width], where theax is the previous
x& [3 \4 |1 X; @% axes, x and y are the location and width is the wind
. Z+ b. H M+ h' T! `5 J9 h) y% rose width relative to theax width (default=1/5)# l$ _$ d0 O& w
% -iflip, flip the intensities as they go outward radially, ie,$ k+ K& Q: v* g+ L2 v. u
% highest values are placed nearest the origin [{0} 1]+ F2 y4 e, h& b) k
%; v. V' J# z5 T3 U1 e- J
% Output:8 o, k# [1 \" O9 y
% HANDLES Handles of all lines, fills, texts
: F3 u6 n1 F/ u( b%
7 X, g: C4 |8 e& L% Examle:
2 V* _' p! _) a) V7 _2 G( M% d=0:10:350;- `+ d5 f# j8 o! W p2 b- I
% D=[];1 I' G5 p; u* C6 {7 ]! c- S
% V=[];
) w" f4 S1 o/ |3 M) i; E' A% for i=1:length(d)
. a" Q8 R8 ^9 l1 A% n=d(i)/10;
. e3 q" z% Y% v0 {, o9 D9 b# @% D=[D ones(1,n)*d(i)];; y& s+ R" y# o# Z3 L7 U: M9 M
% V=[V 1:n];" r& n( u" B* k0 \$ ]
% end9 k& ], }0 ?( r3 g+ T
%
. {4 E3 n+ j/ A, ^/ U5 t& J( O% figure
0 ~- B5 L# i, y* a' @6 m5 L% wind_rose(D,V)
7 ^5 }1 O1 Z7 X# ~1 V+ c%
/ o7 K5 |0 ~& y* Q4 K/ G7 i- L% figure
. U9 g( d j O' W% wind_rose(D,V,'iflip',1). n8 X' z0 v* Q
%9 F& |2 d5 [% |& z/ u7 r
% figure. T. w- O% Q" G8 H9 |) u
% wind_rose(D,V,'ci',[1 2 7],'dtype','meteo')
/ q+ C7 s) J; B& R6 n5 T6 z# _%6 `8 U+ ^/ @9 n5 V+ N$ \9 {* R
% % place it on a previous axes:7 R4 Y" {2 \0 C
% ax=axes;, L0 k$ c- m% R( @: n' q, a
% plot(lon,lat)
% L* S9 o3 y, S# ]% wind_rose(D,V,'ax',[ax x y 1/3])$ k) u! D' p2 q( a9 }- u( p2 P
%
; I, [, M Y% ~% n8 m+ a% MMA 26-11-2007, mma@odyle.net
. }& X* Y( _* f- D, m0 t9 \' U' }1 Q3 M; |4 j" b: M3 A
% IEO, Instituto Espa?l de Oceanograf?
& w8 [0 i# N. j: ?& ]1 N% La Coru?, Espa?
9 {6 M( \' r) \/ G0 C7 [! J0 D( f3 b% A. j
% 10-12-2007 - Added varargin ci and n (nAngles removed as input)# K( K& E7 i+ ~
% 17-12-2007 - Added varargin ax, colors
) H" [( b% s# y* f9 c" z% 22-02-2008 - Added varargin dtype
. |/ u' v+ A# F) w% T$ l: s* s% 08-05-2008 - Bug fix (bar at dir=0 could be incorrect in some cases)
9 p- c* M& W; i) Q. g/ p0 x3 t% 14-05-2008 - Added varargin iflip
- {8 s0 z2 `$ a2 o5 y$ a
% ^1 N8 c A& D%figure;/ E* S- H$ U: }- Z2 ?. Y
handles=[];
% v3 R/ y1 ?) } s6 S
8 [% B: s- |/ s6 A( @; L% varargin options:
+ ?/ T P0 P7 }& Y5 Ldtype='standard';
% P8 |# H. I3 U' pnAngles=16;7 `5 o/ i, @% O3 R: c1 V' g
ri=0.01; K$ T7 R1 \4 T4 w
quad=1;
3 h% k0 u& E* j. b/ V# y* @legType=2;$ z2 k' L e" {/ p: @8 p
percBg='w';0 U0 X5 U @% O' j
% percBg=[204/256 204/256 204/256];%ͼ}ѳްɫ1 G4 e$ d! S" `1 I9 h0 K! o( l/ D
titStr='';
/ d. \$ s7 R( x, |7 r* L8 alegStr='';, `( Z' m2 p8 V- P& `( R% s3 F
cmap=jet;
' w$ j; k, n$ z1 o5 @colors=[];
' {) `0 j7 G# V9 p9 @: O! J/ GAg=[]; % intensity subdivs.
7 J& W- D. G, ~( sci=[]; % percentage circles" u% T. e9 K. y6 J* _
lineColors='k'; i- x9 Y2 a& Y5 N. Q, H
borderColor='none';8 a S" P- `, _) d
onAxes=false;; O6 ^7 H' t; x! x
iflip=0;* a# D0 m; `' ?7 H
" Y# d7 D/ ]" g0 k, `0 u" q& J
vin=varargin;
?7 e/ s3 ~; [0 J5 i) L4 \for i=1:length(vin)2 w; o9 ?$ l+ g1 z6 m _
if isequal(vin{i},'dtype')2 E2 P- r* P! [+ n- r
dtype=vin{i+1};' e X4 ? L3 P2 r7 O2 { ?% n
elseif isequal(vin{i},'n')3 u2 T4 A9 ]) ^1 A' l, r3 I% H/ f
nAngles=vin{i+1};/ T( B$ f0 ?5 ]# y% ^3 f
elseif isequal(vin{i},'ri')
6 \% {# b: r {/ d: s' g, _; ?+ D ri=vin{i+1};
8 N# [/ M, P n" S: ] elseif isequal(vin{i},'quad'): U1 m$ d* K$ Z+ o7 a
quad=vin{i+1}; E6 [. z# ?7 R. L5 ?, [
elseif isequal(vin{i},'legtype')& [: N- m. ?4 s; A9 B; Y
legType=vin{i+1};2 @; r. S0 N: X* ~
elseif isequal(vin{i},'percbg')* B5 ^) I* I' F" O
percBg=vin{i+1};
3 h o7 Q; U/ e! I8 t( l% c% ? elseif isequal(vin{i},'labtitle')
+ W" ^! p& L% s5 ~' E7 S6 v titStr=vin{i+1};- r$ M& c5 M+ t9 @
elseif isequal(vin{i},'lablegend')
. a- j* O! }5 H# j, E7 ^2 w! i legStr=vin{i+1};
. X* s/ o3 [& s/ v7 w elseif isequal(vin{i},'cmap')
. Z/ \) M0 u# r& z$ h% a$ E2 G3 ~: A cmap=vin{i+1}; k* x \9 k, F2 d5 F$ t- \
elseif isequal(vin{i},'colors')- o. J/ Q) r$ o8 M( p
colors=vin{i+1};: \% X5 n- r) H5 x: c
elseif isequal(vin{i},'di')
7 d; I8 b1 i h% l i Ag=vin{i+1};
' y; k, B3 _0 X. g, V& R elseif isequal(vin{i},'ci')6 ]6 g* T( ^( K5 W6 f& Q8 J$ o
ci=vin{i+1};
! J; b6 U3 P: u4 c elseif isequal(vin{i},'lcolor')" a# h$ ]' S; S4 O
lineColors=vin{i+1};" B+ @4 ^1 h% F$ i& J% j- `3 V' T
elseif isequal(vin{i},'bcolor')
0 T( d/ ^% M7 x# p8 Y- k1 t) U) y borderColor=vin{i+1};
5 N' k# N5 d: A* t9 K- u4 e" c elseif isequal(vin{i},'ax')) g; n8 E% r" W
ax=vin{i+1};
: ^ W# t3 q% m7 _5 a: R try
7 r( }/ l$ I! j, V7 c onAxes=ax(1);9 M9 |% @! p3 i6 y" F4 z! b
onAxesX=ax(2);1 N& E/ b+ C2 E3 u9 w1 \
onAxesY=ax(3);
+ G0 B1 X( H" ]; q onAxesR=ax(4);
- C5 o4 J& E, `6 j! W' h8 U" ^: X2 e catch* }+ i* A0 G( f( v/ U0 J7 @4 b
disp(':: cannot place wind rose on axes, bad argument for ax')* u% O0 D Q4 \( u
return5 @5 j: T R1 O% |: t7 f/ c; B
end5 V$ G! p1 v/ _
elseif isequal(vin{i},'iflip')' e8 ]+ V' C) @7 B' {& [
iflip=vin{i+1};; L! n8 m% i) B9 E- M/ p
end
! h( p" K2 X8 p; r5 S, d3 Nend
/ D+ }" y* g/ z
# i+ D; Q g; q4 i0 l# \8 h% other options:5 ?( F* r8 f' {. O1 k, G( v" F) z
% size of the full rectangle:- V8 A/ N. S* Y6 J
rs=1.2;
! ?9 b w# O) ?* l' Erl=1.7;
( x! y+ C- D, i" k" |; K
. h9 `1 v# [0 n% directions conversion:) o' ~0 ?3 t) a. @' y l
if isequal(dtype,'meteo')" w0 X/ l. n4 G9 s7 t+ H8 U3 o
D=mod(-90-D,360);8 k- w8 L1 d( e9 K0 V
% D = mod(90-D,360);
+ k5 U6 v( A6 @" hend$ `- I" L9 Q( t0 U- F. z: q
' m2 o% J! K: j; r- j+ I
X/ N- l: u+ ]# H4 t. u% angles subdivisons:
7 X, j: K, k9 i: hD=mod(-270 - D,360);4 r% E( K: L1 D6 z% n
Ay=linspace(0,360,nAngles+1)-0.5*360/nAngles;8 R* Q. |. T. O" R# A3 H% f- F: G4 `
+ E* E* ^7 M' {: i0 ^# z
+ _, q4 P, y/ x2 C4 L% calc instensity subdivisions:
7 {' J8 N8 I& w2 c7 dif isempty(Ag)1 S3 O$ F0 K) T5 E% t
% gen Ag:
8 b" j* f7 u+ W% F# ?- |6 |; R f=figure('visible','off');
8 r7 X! i# Z7 z$ ^" o3 C plot(F); axis tight;- }+ x; u7 T' R# `9 u
8 g l: j0 {: @ P6 L) d
yl=get(gca,'ytick');! s% H6 P0 l& v" a6 R
close(f)
# }/ G$ D3 Q# R dyl=diff(yl); dyl=dyl(1);5 Q5 P* O2 C3 A$ X
if min(F)>yl(1), yl=[yl(1)-dyl yl]; end) `; D3 V# r a0 i- p
if max(F)>yl(end), yl=[yl yl(end)+dyl]; end: b& K3 d1 P3 T
Ag=yl;+ f3 f+ d8 [, r/ X! z0 r
end: a1 }; C5 q( U- s l' d
4 h- f& I/ V. }( A+ |- k' R7 j/ D
IncHiLow=1; % include values higher and lower that the limits of Ag.
- l; D! h) A: \for i=1:length(Ay)-1" [( ?, u0 S8 t- `
if i==16 N! h" Z" }. @( q# J
I=find( (D>=Ay(i) & D<Ay(i+1)) | D>=Ay(end));6 u: T; ]$ y, k# }% V1 r
else( z6 ^/ s% |" g: ]$ _
I=find(D>=Ay(i) & D<Ay(i+1));
5 D( x+ c( F: T9 f/ [. l% l8 m" S. F) V end5 M6 W4 x/ B9 K. f$ W
b=F(I);; S. Y# \, m4 V4 _( r( X
% e& U7 [2 u8 z1 `
for j=1:length(Ag)-11 J- u2 r; I, U' h
J=find(b>=Ag(j) & b<Ag(j+1));1 ?0 w2 R+ _9 i
E(i,j)=length(J);
8 \: ]& W" l( t6 n6 d0 j% y end5 C2 ]! R- Z3 n3 h, ~* V5 |# g8 z
! X* {& R5 b8 `5 y! w0 F) Q: Z if IncHiLow, h$ z; g$ T: ]' B
E(i,1)=length(find(b<Ag(2)));
: `5 B. |' h I0 ?9 A E(i,end)=length(find(b>=Ag(end-1)));
$ C2 t# o4 ~, o9 A0 u7 E Q end
9 ^- \! g; C) c6 M& _+ |end& } g" J' y9 P$ A
b=sum(E,2)/length(D)*100;( J% r6 B1 K+ T7 a# ?
8 Z; {6 I0 n J6 k
% check if has values higher or lower than the Ag limits# {6 B; j1 w( x$ x% q1 f. u
hasH=length(find(F>=Ag(end)));
3 ?& Y {6 C- ahasL=length(find(F<Ag(1)));/ b% J( K! i) w3 \' j0 f6 G) A
( p7 d) ^: H& M: d$ \5 J5 X0 s% calc number of percentage circles to draw:
/ ?6 K/ y4 c6 }1 o6 A; ?if isempty(ci)
0 i2 Q9 l% p5 n3 m: i7 e2 V dcircles=[1 2 5 10 15 20 25 30 50];
( z1 U( |6 d9 T* i ncircles=3;
$ \8 |7 n( G# z) o! h2 E) e, Y d=abs(1./(dcircles/max(b))-ncircles);
$ r, `# N" m/ V! q' G2 Q- \ i=find(d==min(d));
% g- j) U) G: l& V9 c: M d=dcircles(i(1));
' Q/ h' O% a* p if d*ncircles<max(b)
* G/ H' h7 ?% ]) B ncircles=ncircles+1;
1 R: J' y) h; K) g, O+ t; K end
* ~2 g% F$ c/ @' g C ci=[1:ncircles]*d;2 R2 w0 ^% p( k0 g5 j: ^
g=ncircles*d;
' v" G$ E# O) M8 celse
: T+ v# t4 w$ i1 a ncircles=length(ci);
6 j9 p9 T! {& r }4 t, ~ g=max(max(ci),max(b));: v, c% r8 G' I/ P0 }6 X5 Q( E1 q
end D; m, p3 `: Y1 K+ g2 u6 K
1 V5 U6 P6 T$ M" x& D
0 u2 c$ U$ F6 u9 |9 O2 ?% plot axes, percentage circles and percent. data:) X! J& t9 i1 G8 J; W
wrAx=axes('units','normalized');
) A+ h2 F/ p, t# t2 Uri=g*ri;
: P3 j$ E1 p8 j* i9 r$ ~& _handles(end+1)=fill([-rs*g rl*g rl*g -rs*g],[-rs*g -rs*g rs*g rs*g],'w',...4 @1 i" ]- s8 ?
'EdgeColor',borderColor);, \3 h8 k. {) z- A, h. v" G
if onAxes
% R# `' P8 l# @8 k2 T) v; s- s set(handles(end),'facecolor','none')
, n7 c/ O+ H' M, ^; E, A" Lend4 T, H7 b1 ~6 i' R% {8 {+ f
hold on
# n( x$ U: c: Y; T2 Khandles(end+1)=plot([-g-ri -ri nan ri g+ri nan 0 0 nan 0 0],...& L+ _% u5 p( g6 X' V3 W' [
[0 0 nan 0 0 nan -g-ri -ri nan ri g+ri],':','color',lineColors);: E1 a* i$ L ^6 G
t0=[0:360]*pi/180;
3 A5 u, a# `* F% h. I) B: `labs=[];4 Y5 g) M) h1 h: P6 f. R5 J
Ang=[1/4 3/4 5/4 7/4]*pi;* p% {. c9 h% D+ J0 c. O2 d
Valign={'top' 'top' 'bottom' 'bottom'};1 N2 z7 i5 e5 r' S
Halign={'right' 'left' 'left' 'right'};
! i, Y) F: o4 Z3 F) |for i=1:ncircles: u6 @7 f# [& @8 ]
x=(ci(i)+ri)*cos(t0);
1 h8 K1 C% z0 G+ \ y=(ci(i)+ri)*sin(t0);
. e1 `! D! C( w7 w$ N5 E" G
& j, ]5 n( z) X( k. N handles(end+1)=plot(x,y,':','color',lineColors);
\# |, Z. }" `: l* K+ x8 n6 ]; Z0 {1 G2 d0 e- B& z
labs(i)=text((ci(i)+ri)*cos(Ang(quad)),(ci(i)+ri)*sin(Ang(quad)),[num2str(ci(i)),'%'],...( k% i5 r) n) |+ s% ^
'VerticalAlignment',Valign{quad},'HorizontalAlignment',Halign{quad},...
7 {. Y& \7 v3 I: T6 Z3 r 'BackgroundColor',percBg,'FontSize',18);
0 `) e" V8 r% ]6 W8 ]9 i% j( P9 Yend
( k y$ y/ ]1 E( s- U4 khandles=[handles labs];
9 Z: U4 L$ g, j# W0 S8 C g( e9 l( j/ O k. N5 g# [5 Y
% calc colors:
5 d1 t0 J/ [; B5 ^7 j6 rif isempty(colors)8 y, }* f6 F. ]! `/ U( f3 U
cor={};* ` S$ b% _7 b3 c
for j=1:length(Ag)-1
' b1 ]5 W# h; |' \/ R; J cor{j}=caxcolor(Ag(j),[Ag(1) Ag(end-1)],cmap);$ d4 I* a. T# u, o2 Q- C
end5 s- R; B0 `2 a
else
5 a) d8 y5 _" w5 Z! R* L* k8 y cor=colors;
1 k9 O% d4 x* ~6 ]* f1 k! Uend' u: t9 j9 F, a6 q! e7 n
( Y! \' s0 C8 q% fill data:
8 k5 v! r3 P9 ^4 J9 N/ f2 \n=sum(E,2);8 F% w: v, L5 N
if iflip, E=fliplr(E); end! Q' H$ O9 e' n* g& \& @
for i=1:length(Ay)-1 _3 k3 |" _2 |! ~5 E
if n(i)" N0 g; U: C( H1 ?0 T
t=linspace(Ay(i),Ay(i+1),20)*pi/180;3 C4 F3 v# L' L* ^
r1=ri;) F' j- s( u$ e
for j=1:length(Ag)-1- y7 W" L/ @# M- X3 G
r2=E(i,j)/n(i) *b(i) +r1;
7 D9 Y" Z, i! j& y0 ?! Z. K! m
8 S( N$ M- l1 L" E d) S. |+ v5 E x=[r1*cos(t(1)) r2*cos(t) r1*cos(fliplr(t))];0 n T7 f7 h# n( J; p
y=[r1*sin(t(1)) r2*sin(t) r1*sin(fliplr(t))];
2 a6 _$ y. i; J2 L3 L7 S+ N& t! R$ ^9 H6 F7 F3 n
if iflip, jcor=length(Ag)-1-j+1;1 W9 t+ D# L3 Y
else, jcor=j;
8 [( s0 |% C+ |7 H1 t end% E. S- U* v8 T! L5 F7 v1 ]
! c! ?& I$ z' {3 L
if E(i,j)>0, handles(end+1)=fill(x,y,cor{jcor}); end I q- d3 V' x; j3 S
r1=r2;* |6 V- J# d- j- V% R, n
end) U" i* a; p2 e
end
& J! i: y7 B- P, eend* k# T1 J O6 n9 s4 R& s0 A, H I
axis equal
2 O$ r# ]' e9 L2 s b) }* Q4 c7 waxis off
: s" S" p4 i6 \3 ?, wuistack(labs,'top')4 X" l0 K6 I2 ^$ U- U
0 G# h4 v( j, z% |2 L3 O
% N S E W labels:
0 J# W: P, R: T8 B7 A; N7 Abg='none';5 b8 `$ j: i2 c7 m U, a" H
args={'BackgroundColor',bg,'FontSize',18};
! z+ @6 L) z3 N! o5 K3 u" Fh(1)=text(-g-ri, 0,'WEST', 'VerticalAlignment','top', 'HorizontalAlignment','left', args{:});! _( u3 x/ w$ U
h(2)=text( g+ri, 0,'EAST', 'VerticalAlignment','top', 'HorizontalAlignment','right',args{:});8 i/ K# i. e9 E
h(3)=text( 0,-g-ri,'SOUTH','VerticalAlignment','bottom','HorizontalAlignment','left', args{:});3 f; t" E( K( ]2 k4 H$ I
h(4)=text( 0, g+ri,'NORTH','VerticalAlignment','top', 'HorizontalAlignment','left', args{:});
! A" ~7 g& V- J8 P6 b9 v/ C
3 c* g) u2 l2 u/ Khandles=[handles h];4 d3 c3 |0 g6 P( f. o) Q
0 k! p1 h, Y1 T Y* x% scale legend:
& ]4 |8 U, T& J: }L=(g*rl-g-ri)/7;
% t6 A2 l" f# q9 F* t% O- \+ Ah=(g+ri)/10;
; O" p: k* `& Y" P0 d7 ^dy=h/3;
+ @* n. r$ z% s H) L
) t' l+ `% B, zx0=g+ri+(g*rl-g-ri)/7;+ j) H4 t1 L5 n* R
x1=x0+L;
" D0 ^, V0 q* P$ w0 {y0=-g-ri;
; k+ o' U6 q8 p- v
7 @1 N7 @5 B; @1 R- Q: r/ Oif legType==1 % contimuous.
/ B$ n a7 o' }8 B1 |. H; g for j=1:length(Ag)-1
7 ?% R3 t8 h! p! C lab=num2str(Ag(j));
# I5 N* q$ T' p K$ q2 k1 u if j==1 & hasL & ~IncHiLow
5 k: C. L9 t6 h+ J: e lab='';5 N Y' Q2 D% l+ z
end
5 W" ], U3 V% L* x y1=y0+h;6 A4 z' c- M9 v) _) e/ I+ ~5 R
handles(end+1)=fill([x0 x1 x1 x0],[y0 y0 y1 y1],cor{j});
! h( i# @1 y; F6 @+ ]* _# E handles(end+1)=text(x1+L/4,y0,lab,'VerticalAlignment','middle','FontSize',18);
8 ]0 ^/ E4 F7 J0 n& r/ ~ y0=y1;
" U0 I3 X* q3 G, m) }1 z5 N& Y+ } end0 J J" g( h2 S. F2 w
if ~ (hasH & ~IncHiLow)( c0 v6 j$ f% _4 J: s$ p! ~& N X
handles(end+1)=text(x1+L/4,y0,num2str(Ag(end)),'VerticalAlignment','middle','FontSize',18);
" A" S3 t4 ]5 g. u' R end
6 q% Q9 O! ]' h* L" x. @elseif legType==2 % separated boxes.
0 y: m6 V& ?8 f, f for j=1:length(Ag)-1
6 e- e6 Q7 o! N9 I$ { lab=[num2str(Ag(j)) ' - ' num2str(Ag(j+1))];0 C& ~% T8 Z' U2 u. |/ |% T
if j==1 & hasL & ~IncHiLow) I& i- ^) l, Q1 E7 g H3 W
lab=['<',num2str(Ag(2))];
4 Q' A1 s9 x( M; ` V% \6 B k end
4 w8 @+ l! A/ w9 d; C* Z if j==length(Ag)-1 & hasH & ~IncHiLow
! |* W3 D$ P: X/ n7 |) S" _ lab=['>=',num2str(Ag(j))];4 u1 A$ ?5 F0 { U* Q
end
$ r4 b! n" O* \& P4 z9 k4 V7 C" |7 B: u; o y1=y0+h;
2 F9 L3 M$ @9 o: i/ H handles(end+1)=fill([x0 x1 x1 x0],[y0+dy y0+dy y1 y1],cor{j});- Z1 n. r6 E: V. ?- v: J$ b: m
handles(end+1)=text(x1+L/4,(y0+dy+y1)/2,lab,'VerticalAlignment','middle','FontSize',18);
1 b! T) R( V0 w$ m y0=y1;
" \9 R4 Z' i* g+ e end7 u- j D1 J8 H$ c
. H/ ~4 S& a2 R2 U( Hend" U' {! _2 P5 X3 V- \7 p( ^7 ^ q
" G7 ?) M$ W) t3 E% D% title and legend label:' [# K4 R. {+ Z, \: d$ r; q
x=mean([-g*rs,g*rl]);( P% U, M. ?8 k. c/ F! q5 ]
y=mean([g+ri,g*rs]);" v% L7 g+ m# u! f& Q2 H
handles(end+1)=text(x,y,titStr,'HorizontalAlignment','center');
1 p( b+ i6 z1 X* E
5 a6 j, t a7 o. u/ [0 e% _x=x0;
' V9 i# y2 s! M4 t4 H) {- Ay=y1+dy;
/ m6 ?- W7 I# K6 s8 zhandles(end+1)=text(x,y,legStr,'HorizontalAlignment','left','VerticalAlignment','bottom');
" Y% o4 x; d8 C i" \& c2 u
8 T& z( _. a$ T: M* Xif onAxes
+ `1 q- J3 X( u place_wr(onAxes,wrAx,onAxesX,onAxesY,onAxesR);$ G9 Y1 Q$ W5 f/ }. m5 J6 L- R
end; p3 A; A9 s- N) @0 N
7 z0 o! ~2 b; v
if nargout==1+ d5 d t* }# V( r# w
varargout{1}=handles;
) K2 m7 d4 W Oend
; s/ b+ \$ X# c' z( u1 c8 F$ c3 P- U
function place_wr(ax,ax2,x,y,width)
; ~8 C) u4 N# N( }9 W, H9 eif nargin < 5) _9 g7 R' B6 T; U
width=1/5;$ F/ W( n* ]! w* y, C; p& h
end
' g* _0 s: S6 Z. x Iuax=get(ax,'units');$ z/ n3 o& z# A- c5 \
pax=get(ax,'position');
# ~- r$ X# @$ f& Lset(ax,'units',uax)
! R8 y9 I% V/ w+ w3 WaxXlim=get(ax,'xlim');* u6 E- A- c$ G$ ~( `* k
axYlim=get(ax,'ylim');2 M' [- P y! l V
8 {9 _' O z& rx_ax2=pax(1)+pax(3)*(x-axXlim(1))/diff(axXlim);
9 Z* v/ W0 C( m, F! g5 `y_ax2=pax(2)+pax(4)*(y-axYlim(1))/diff(axYlim);
" ?( t A2 D* R l5 _/ F, u+ i& f% U/ W4 Y
pax2=get(ax2,'position');
# m) y; v+ U" pwidth=pax(3)*width;# e$ Q1 ~ H/ i) O9 {& c
height=pax2(4)*width/pax2(3);5 g5 u: v5 t1 X! t
pax2=[x_ax2 y_ax2 width height];
: B/ [; K$ t& l- k8 L( [7 e! K5 g- x4 Q4 D: {2 `: W, W2 e+ n
if 10 A# V" ` }% Y3 z- q! v) d
% place at centre of the wr, not the bottom left corner:
" Y4 Q0 S& t4 H W ax2Xlim=get(ax2,'xlim');
) S4 s1 p6 X f ax2Ylim=get(ax2,'ylim');% H7 Z& Q( h3 J* {9 i, P
dx=(0-ax2Xlim(1))/diff(ax2Xlim)*pax2(3);
& x" P+ G% w" e6 l dy=(0-ax2Ylim(1))/diff(ax2Ylim)*pax2(4);6 w7 [& V& a+ \9 F$ U
x_ax2=x_ax2-dx;# ]% ]9 w! d' ^4 F* m
y_ax2=y_ax2-dy;# |$ V! J4 S! \' o9 i
pax2=[x_ax2 y_ax2 width height];
( O' z& [2 B& _- p* Send# A; Z; b- f) L
set(ax2,'position',pax2)
+ l7 M8 D# N4 `, d: h: C$ W% q: D! V' z: ^' N6 d, L1 x
' Y: Z) t9 _& \8 P5 v& F0 o1 |! x# X& S& q
function cor = caxcolor(val,cax,cmap)' C7 s) e; b H3 }8 x8 K, h) ]$ `. m
%CAXCOLOR Caxis color for value
' l/ D. Q- v" c }% Find the color for a given value in a colormap.0 z7 N' D+ q3 U/ Y; R" n1 V
%, F; ]% _' l6 Q/ y3 ^9 B
% Syntax:1 C# q4 |3 K* v- C; D2 K1 g {4 J$ ~
% COLOR = CAXCOLOR(VALUE,CAXIS,COLORMAP), T% h6 T) `" l
%
3 I: {# k7 s8 |% `% Inputs: ]; y( ]4 o( \3 ~" O* i9 H" P
% VALUE
1 d0 o: }: c! k3 [5 r2 L$ _% CAXIS Default is current caxis
7 J1 g p- N, O* c& V: z' O4 w6 \9 e. _% COLORMAP Default is current colormap
2 `- ^0 l( g: }6 a* y" Y+ c. Y%" i) k3 N! i; K/ c |! x9 b: f
% Output:
" x9 _, Q6 X* P/ l5 c% COLOR RGB color vector' g! O. H* |( `9 w* Z+ s
%
/ L) e2 X b- Q6 _) A7 U% Example:6 h/ q" e8 W0 D: q0 D
% figure" ^0 d2 b# a: o* I
% pcolor(peaks)
4 w' K) M. m; u% color=caxcolor(0);
3 |/ I5 `8 F6 q1 U% set(gcf,'color',color)
E8 N. X0 N/ l- z- {. A v%
' L, j B- O: {, C% MMA 28-5-2007, martinho@fis.ua.pt
l* ^6 @4 D" ~9 ?0 J2 j W6 D% I; A8 d) M8 T0 U# j+ R
% Department of Physics8 t! R) I E7 M* }, q" {
% University of Aveiro, Portugal$ a- @0 y3 V1 S2 Q
1 ^" b1 m6 ^3 S1 ~4 I4 [2 Q; k
if nargin < 3
) S4 ^0 o( O! ?" Q2 \cmap=jet;6 N& n2 A) m9 T+ L
end9 e& h0 x4 h( G" j2 O7 q
if nargin < 2
0 W/ o& O; c# q1 t% N8 e7 x cax = caxis;
" Q- n: ^3 @: m8 d" k' C cmap=jet;
0 p0 i6 Z. Q0 z; M1 T' pend
& |2 S& k' f E3 k: i5 n
( B- `: [+ R4 r' In=size(cmap,1);
4 |: O* O- Q; E3 g: }i= (val-cax(1))/diff(cax) * (n-1) +1;
# t8 `+ [7 h8 f; g A% Y% Pa=i-floor(i);
0 y/ s% k: w& I/ @7 Wi=floor(i);# O# c% y2 q. p. f( Q& O7 x
) `6 h0 S* @6 j2 `
i=min(i,n);9 Y& w; o) o3 r0 l x
i=max(i,1);4 f0 }& j3 k! F+ r0 o
1 _2 i4 m6 ~% c! h: C b+ Q" @if i==n
$ v0 N( E* a" ? cor=cmap(n,: );
5 ]. T- n& m1 A/ yelseif i==1# j! T+ z! V, M; e1 w' k3 F9 O
cor=cmap(1,: );! d& _ H4 [, G4 G* c8 p9 V
else
, v" w( K, a& S; ^% r7 {; ~3 a0 q cor=cmap(i,: )*(1-a) + cmap(i+1,: )*a;9 B$ [6 d3 L! j
end
; ] L7 n4 T4 W8 I" W0 v8 E$ o% w" b0 D
|
|