matlablegend(matlab 设置legend「建议收藏」)

发布时间:2025-12-10 19:51:24 浏览次数:17

matlab 设置legend「建议收藏」-matlab legend()函数

matlab 设置legend(比较全面)「建议收藏」legend(‘sin(x)’,’cos(x)’,’Location’,’North’);Matlab中有许多位置可以选择:’North’insideplotboxneartop’South’insidebottom’East’insideright’West’insideleft’NorthEast’i_matlablegend透明

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.  clearclcclose 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

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477