Matlab中图例的位置(图例放在图的上方、下方、左方、右方、图外面)等

一、图例默认位置

默认的位置在NorthEast

bash 复制代码
r = 10;
a = 0;
b = 0;
t=0:0.1:2.1*pi;
x=a+r*cos(t);
y=b+r*sin(t);
A1=plot(x,y,'r','linewidth',4);%圆
hold on
axis equal
A2=plot([0 0],[1 10],'b','linewidth',4);%直线
legend([A1,A2],'圆形','line')

二、通过Location对legend的位置进行改变

变为North

bash 复制代码
r = 10;
a = 0;
b = 0;
t=0:0.1:2.1*pi;
x=a+r*cos(t);
y=b+r*sin(t);
A1=plot(x,y,'r','linewidth',4);%圆
hold on
axis equal
A2=plot([0 0],[1 10],'b','linewidth',4);%直线
legend([A1,A2],'圆形','line','Location','North')

三、图例放在图的其他位置

设置 位置
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

直接替换即可

四、图例放在图的外面

bash 复制代码
r = 10;
a = 0;
b = 0;
t=0:0.1:2.1*pi;
x=a+r*cos(t);
y=b+r*sin(t);
A1=plot(x,y,'r','linewidth',4);%圆
hold on
axis equal
A2=plot([0 0],[1 10],'b','linewidth',4);%直线
legend([A1,A2],'圆形','line','Location',' WestOutside')

五、只显示一个曲线

bash 复制代码
r = 10;
a = 0;
b = 0;
t=0:0.1:2.1*pi;
x=a+r*cos(t);
y=b+r*sin(t);
A1=plot(x,y,'r','linewidth',4);%圆
hold on
axis equal
A2=plot([0 0],[1 10],'b','linewidth',4);%直线
legend([A1],'圆形','Location',' WestOutside')
相关推荐
移远通信13 分钟前
常见问题解答
开发语言·php
初见无风17 分钟前
3.1 Lua代码中的元表与元方法
开发语言·lua·lua5.4
逻极31 分钟前
Rust流程控制(上):if_else与match模式匹配
开发语言·后端·rust
小雨下雨的雨35 分钟前
Rust专项——其他集合类型详解:BTreeMap、VecDeque、BinaryHeap
开发语言·后端·rust
渡我白衣36 分钟前
C++世界的混沌边界:undefined_behavior
java·开发语言·c++·人工智能·深度学习·语言模型
剑海风云1 小时前
JDK 26:HTTP/3 支持已可在 HTTP 客户端 API 中使用
java·开发语言·http
下一站丶1 小时前
【JavaScript性能优化实战】
开发语言·javascript·性能优化
GIS好难学1 小时前
Three.js 粒子特效实战③:粒子重组效果
开发语言·前端·javascript
景彡先生1 小时前
Python NumPy广播机制详解:从原理到实战,数组运算的“隐形翅膀”
开发语言·python·numpy
不光头强1 小时前
springDI注入
java·开发语言