博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Matlab中legend的位置
阅读量:2012 次
发布时间:2019-04-28

本文共 2516 字,大约阅读时间需要 8 分钟。

Matlab中legend默认的位置在NorthEast,如图所示​

%Matlab中legend的位置设置clcclear close allNpoint = 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的位置设置clcclear close allNpoint = 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中有许多位置可以选择:

'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的选择clcclear close allNpoint = 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')

在这里插入图片描述

如果只想显示第1、3、5条,也很简单

%Matlab中legend的选择clcclear close allNpoint = 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')

在这里插入图片描述

此外,还可以使用Orientation对legend进行横向排列

%Matlab中legend的横排,注意,Location位置改变为Northclcclear close allNpoint = 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的clcclear close allNpoint = 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','Box','off')

在这里插入图片描述

转载地址:http://guzxf.baihongyu.com/

你可能感兴趣的文章
volatile关键字
查看>>
Request_继承体系
查看>>
前端权限控制:获取用户信息接口构造数据
查看>>
七牛云存储:断点续传
查看>>
字节流复制文本文件【应用】
查看>>
私钥加密私钥解密
查看>>
Java判断字符串是否为数字(浮点类型也包括)
查看>>
ubuntu opencv-python 安装很慢问题
查看>>
MySQL5.7版本修改了my.ini配置文件后mysql服务无法启动问题
查看>>
Exception in thread “main“ java.sql.SQLException错误之一: Column Index out of range, 0 < 1.
查看>>
C3p0连接池连接mysql出现: com.mchange.v2.resourcepool.BasicResourcePool
查看>>
Azkaban体系结构
查看>>
机器学习之重头戏-特征预处理
查看>>
synchronized底层实现及锁的升级、降级
查看>>
PermGen space-永久区内存溢出
查看>>
Maven继承和聚合
查看>>
Apache Kafka:优化部署的 10 种最佳实践
查看>>
Leetcode 35. 搜索插入位置 c#
查看>>
[9] JMeter-常用函数的使用
查看>>
[12] JMeter-结果分析之图形图表
查看>>