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')
相关推荐
山楂树の2 小时前
Java 泛型:泛型类、泛型方法、泛型接口与通配符
java·开发语言·笔记
利威尔xu2 小时前
2026-11-18-Go接口幂等设计实战
开发语言·后端·golang
eggwyw4 小时前
linux下的C\C++多进程多线程编程实例详解
开发语言·c++
布莱克6054 小时前
Swift 枚举详解:从基础语法到关联值与模式匹配
开发语言·ios·swift·枚举
布莱克6054 小时前
Swift 闭包详解:从语法到实战的完整指南
服务器·开发语言·ios·ssh·swift·闭包
小七在进步5 小时前
string的实现(3)
开发语言·c++·笔记·visual studio
专注仿真6 小时前
基于 AFSIM 的智能体训练:多智能体强化学习篇 —— QTRAN 算法实战
开发语言·python·算法·php·强化学习·afsim智能体·仿真训练
Funlang8 小时前
RISC-V 上的 Fun:第四套机器码
开发语言·risc-v·龙芯
feixing_fx16 小时前
第一个 JS 程序:在浏览器控制台和 Node 中分别运行
开发语言·前端·javascript·前端框架·ecmascript
Evand J17 小时前
【MATLAB例程】二维IMM-UKF定位,基于四个基站的AOA与测距辅助
开发语言·matlab