EDA365电子论坛网

标题: Matlab绘图中legend的终极用法 [打印本页]

作者: uqHZau    时间: 2020-4-22 09:41
标题: Matlab绘图中legend的终极用法

基本用法:

legend({'str1','str2','strn'});

高级用法1:指定legend显示的位置:

legend({'str1','str2','strn'},1);

legend({'str1','str2','strn'},2);

legend({'str1','str2','strn'},'Location','SouthEast');

可选的位置很多:

North:Inside plot box near top
+ w  E' M! C; u& f* ^South:Inside bottom
& w' c7 a% ~* a, Q- }1 a" O8 FEastI:nside right
& Y8 x/ h' ?6 E- Q. Y& g" Q$ I5 @West:Inside left* U$ D" a* Q/ Y: }- I: v: [
NorthEast:Inside top right (default)2 i/ U; O: d* S. v3 G) K" S
NorthWest:Inside top left( X! A1 U' W: V7 U8 {: s& |
SouthEast:Inside bottom right0 U" X. X. i; V; Q. G0 s
SouthWest:Inside bottom left' ^! L3 J5 V) e7 z4 v
NorthOutside:Outside plot box near top2 [9 c3 P( y, `) j: N* J. r
SouthOutside:Outside bottom
# B. x+ x( W$ gEastOutside:Outsideright
7 [" ~. b3 J, M1 K1 `WestOutside:Outside left: C% S" n! b" F7 c- A2 ~5 K( |7 f
NorthEastOutside:Outside top right
; q2 x( _2 g  C( INorthWestOutside:Outside top left
# k& J( {# u! G9 w; |SouthEastOutside:Outside bottom right6 G  {9 P6 P2 I; L. ?
SouthWestOutside:Outside bottom left
1 L& U/ u  ~/ ?1 T$ J. ABest:Least conflict with data in plot
' j/ I& `+ r+ o' d6 ZBestOutside:Least unused space outside plot

通常,用'Best‘比较不错

高级用法2:指定显示某几条曲线的legend:

方法1:复杂到吐血

例如你有25条曲线,想显示其中1,6,11,16,21的legend,则

for i = [2:5 7:10 12:15 17:20 22:25]
' M/ C1 r7 E# ]" X- z9 ]set(get(get(H(i),'Annotation'),'LegendInformation'),'IconDisplayStyle','off');6 }8 [& f3 a1 e3 W+ d0 D
end
" m) k/ n7 v2 Y% D! A# Slegend('1','6','11','16','21');

方法2:简单到郁闷

H = plot(data);
2 w/ W* G9 Y9 U4 Ilegend(H([1 6 11 16 21],'1,'6','11’,'16','21');

高级用法3:legend横排

hl = legend(H([1 6 11 16 21],'1,'6','11’,'16','21');
3 P* F. E7 I. mset(hl,'Orientation','horizon')

高级用法4:不显示方框:

hl = legend(H([1 6 11 16 21],'1,'6','11’,'16','21');* A" q* {; d+ V" N0 Z
set(hl,'Box','off');

5 J# C/ G" S9 t
% S0 t/ c6 G+ z
+ m8 L" M- ^' ~! A; D3 e! s; l2 y2 p4 u

作者: yin123    时间: 2020-4-22 13:16
Matlab绘图中legend的终极用法




欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/) Powered by Discuz! X3.2