matlab 设置legend(比较全面)

本文详细介绍了在Matlab中如何自定义图例的位置、排列方式、形状、大小及颜色等属性,包括去除图例边框,使其不遮挡数据线条,以及在一张图上显示多个图例的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

早起CaiCai

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值