matlab画图 legend的位置

Matlab中legend默认的位置在NorthEast,如图所示​
%Matlab中legend的位置设置
clc
clear
close all
Npoint = 100;
x = linspace(0,4*pi,Npoint);
y1 = sin(x);
y2 = cos(x);
H = plot(x,y1,x,y2);
legend(‘sin(x)’,‘cos(x)’);
Matlab中legend的位置

然而,我们却可以通过Location对legend的位置进行改变,变为North,如图所示
%Matlab中legend的位置设置
clc
clear
close all
Npoint = 100;
x = linspace(0,4*pi,Npoint);
y1 = sin(x);
y2 = cos(x);
H = plot(x,y1,x,y2);
legend(‘sin(x)’,‘cos(x)’,‘Location’,‘North’);
Matlab中legend的位置
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
Matlab中还可以选择某条曲线legend的指定显示
%Matlab中legend的选择
clc
clear
close all
Npoint = 101;
x = linspace(0,10,Npoint);
y1 = besselj(1,x);
y2 = besselj(2,x);
y3 = besselj(3,x);
y4 = besselj(4,x);
y5 = besselj(5,x);
H = plot(x,y1,x,y2,x,y3,x,y4,x,y5);
legend(‘First’,‘Second’,‘Third’,‘Fourth’,‘Fifth’,‘Location’,‘NorthEastOutside’)
Matlab中legend的位置
如果只想显示第1、3、5条,也很简单
%Matlab中legend的选择
clc
clear
close all
Npoint = 101;
x = linspace(0,10,Npoint);
y1 = besselj(1,x);
y2 = besselj(2,x);
y3 = besselj(3,x);
y4 = besselj(4,x);
y5 = besselj(5,x);
H = plot(x,y1,x,y2,x,y3,x,y4,x,y5);
h1 = legend(H([1 3 5]),‘First’,‘Third’,‘Fifthth’,‘Location’,‘NorthEastOutside’)
Matlab中legend的位置
此外,还可以使用Orientation对legend进行横向排列
%Matlab中legend的横排,注意,Location位置改变为North
clc
clear
close all
Npoint = 101;
x = linspace(0,10,Npoint);
y1 = besselj(1,x);
y2 = besselj(2,x);
y3 = besselj(3,x);
y4 = besselj(4,x);
y5 = besselj(5,x);
H = plot(x,y1,x,y2,x,y3,x,y4,x,y5);
h1 = legend(H([1 3 5]),‘First’,‘Third’,‘Fifthth’,‘Location’,‘North’);
set(h1,‘Orientation’,‘horizon’)
Matlab中legend的位置

Matlab中legend的位置
参考:
http://www.360doc.com/content/14/0722/17/13670635_396317423.shtml
http://blog.sina.com.cn/s/blog_7db803c10102weyk.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值