
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');
参考文献
doc legend
Site:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
另外,去掉legend边框,可以参考:
legend('x','y')
legend('boxoff')

写两次就好了。matlablegendmatlablegend我最初尝试着写成legend('x','y','boxoff')是不行的。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
修改legend的字体:
legend1=legend('x','y');
set(legend1,'FontName','Times NewRoman','FontSize',12,'FontWeight','normal');
修改legend位置:
i=0;%i=0,自动调整最佳位置;i=1,右上;i=2,左上;i=3,左下;i=4,右下;
legend1=legend('x','y',i);
20160518
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
最好的说明文档,当然是帮助文档:
matlab:
doc legend
legend('hide'), legend(axes_handle,'hide') makes the legend in thecurrent axes or the axes specified by axes_handle invisible.
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-39889-1.html
如果说在一起是注定的
但那是自己造的
两个字