Matlab中legend的位置
发布日期:2021-07-01 04:03:37
浏览次数:4
分类:技术文章
本文共 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)');
然而,我们却可以通过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')
转载地址:https://miracle.blog.csdn.net/article/details/115922032 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月25日 11时14分00秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
iOS中 单例设计模式 的使用方法
2021-07-06
GCD使用 串行并行队列 与 同步异步执行的各种组合 及要点分析
2021-07-06
iOS开发------程序实现国际化Localizable
2021-07-06
SDWebImage 原理及使用
2019-05-03
iOS Runloop详细介绍及应用示例(持续更新)
2019-05-03
iOS runloop与定时器的使用
2019-05-03
GCD定时器使用笔记 及 详细分析
2019-05-03
结合一道面试题 看c语言运算符的执行顺序
2019-05-03
Objective-C的内省方法介绍
2019-05-03
Objective-C 内存管理 看这个就够啦
2019-05-03
IOS开发--微信支付
2019-05-03
iOS 微信支付 实用教程
2019-05-03
UIViewController的基本概念与生命周期
2019-05-03
最新方法制作自己的cocoapods开源框架的详细步骤
2019-05-03
Getting start with OCMock in you unit test
2019-05-03
李洪强和你一起学习前端之(1)Html基础
2019-05-03
李洪强iOS经典面试题142-第三方框架及其管理
2019-05-03
李洪强经典面试题38
2019-05-03
我们必须自学
2019-05-03