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')
相关推荐
shykevin3 小时前
python开发Streamable HTTP MCP应用
开发语言·网络·python·网络协议·http
我不是程序猿儿3 小时前
【C#】 lock 关键字
java·开发语言·c#
漫路在线4 小时前
JS逆向-某易云音乐下载器
开发语言·javascript·爬虫·python
小辉懂编程4 小时前
C语言:51单片机实现数码管依次循环显示【1~F】课堂练习
c语言·开发语言·51单片机
醍醐三叶5 小时前
C++类与对象--2 对象的初始化和清理
开发语言·c++
向上的车轮6 小时前
MATLAB学习笔记(七):MATLAB建模城市的雨季防洪排污的问题
笔记·学习·matlab
Magnum Lehar6 小时前
3d游戏引擎EngineTest的系统实现3
java·开发语言·游戏引擎
Mcworld8576 小时前
java集合
java·开发语言·windows
成功人chen某6 小时前
配置VScodePython环境Python was not found;
开发语言·python
海绵宝宝贾克斯儿7 小时前
C++中如何实现一个单例模式?
开发语言·c++·单例模式