legend('sin(x)','cos(x)','Location','North');
Matlab中有许多位置可以选择:
'North' inside plot box near top
'South' inside bottom
'East' inside right
'West' inside left
'NorthEast' inside top right (default for 2-D plots)
'NorthWest' inside top left
'SouthEast' inside bottom right
'SouthWest' inside bottom left
'NorthOutside' outside plot box near top
'SouthOutside' outside bottom
'EastOutside' outside right
'WestOutside' outside left
'NorthEastOutside' outside top right (default for 3-D plots)
'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
水平排列
h1 = legend(H([1 3 5]),'First','Third','Fifthth','Location','North');
set(h1,'Orientation','horizon')
不要方框
PS:不要方框,此时图例为透明的颜色,不会遮挡住数据线条
h1 = legend(H([1 3 5]),'First','Third','Fifthth','Location','North');
set(h1,'Orientation','horizon','Box','off')
参考连接
http://blog.sina.com.cn/s/blog_7db803c10102weyk.html
legend详细介绍
PS:legend(vsb1)也可设置图例的:隐藏、表现、介于两者之间,没试出其效果
如果想要在一张图上显示2个图例,需要加上下面这句话
ah=axes('position',get(gca,'position'),'visible','off');
呈现效果如下:
修改legend形状、大小等,添加标题等
添加标题
添加颜色、大小等
% Modify the legend appearance by setting Legend properties.
clear
clc
close all
rdm = rand(4);
plot(rdm)
lgd = legend('Line 1','Line 2','Line 3','Line 4');
lgd.FontSize = 12;
lgd.TextColor = 'blue';
lgd.NumColumns = 2;
lgd.Location = 'southwest';
leg.Orientation = 'vertical';
title(lgd,'My Legend Title');
参考链接:https://ww2.mathworks.cn/help/matlab/ref/legend.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/35966.html