您的位置:首页 > 编程语言 > MATLAB

matlab绘图中legend的终极用法

2013-06-18 11:46 417 查看
转自:http://hi.baidu.com/keyflying/item/7b39e9bbdcaceba5ebba936f

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%持续更新。 当前: 20100108 %

%仅作笔记。 作者: keyflying %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

legend有时候挺烦人的,尽管大多时候挺好用。

基本数据:

data = rand(25)+repmat(1:25,25,1);

H = plot(data);

基本用法:

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

South:Inside bottom

EastI:nside right

West:Inside left

NorthEast:Inside top right (default)

NorthWest:Inside top left

SouthEast:Inside bottom right

SouthWest:Inside bottom left

NorthOutside:Outside plot box near top

SouthOutside:Outside bottom

EastOutside:Outsideright

WestOutside:Outside left

NorthEastOutside:Outside top right

NorthWestOutside:Outside top left

SouthEastOutside:Outside bottom right

SouthWestOutside:Outside bottom left

Best:Least conflict with data in plot

BestOutside: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]

set(get(get(H(i),'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

end

legend('1','6','11','16','21');

方法2:简单到郁闷

H = plot(data);

legend(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');

set(hl,'Orientation','horizon')

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

hl = legend(H([1 6 11 16 21],'1,'6','11’,'16','21');

set(hl,'Box','off');

参考文献

http://www.mathworks.cn/access/helpdesk/help/techdoc/creating_plots/braliom.html

doc legend

#Matlab
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: