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')
相关推荐
mayaairi2 分钟前
JS DOM节点操作完全指南:增删改查与性能优化
开发语言·javascript·性能优化
Demon--hx3 分钟前
多态实现原理
开发语言·c++
wanglei2007086 分钟前
消息队列的协作模式
开发语言·python
jimy125 分钟前
拷贝构造时,不用引用的话,按值传参会无限递归调用拷贝构造函数
开发语言
LccKyI28 分钟前
# C# 基础编程 面试题汇总(一)
开发语言·c#
CODER030431 分钟前
win11系统编译安装cuda版llama-cpp-python(踩完所有的坑)
开发语言·python·llama
神仙别闹36 分钟前
基于C语言+SQLite 实现(控制台+图形界面)图书管理系统
c语言·开发语言·sqlite
何以解忧,唯有..1 小时前
LangChain 模型调用方法总结:invoke、batch、stream 的入参与出参
开发语言·langchain·batch
SamChan901 小时前
Python+ReportLab自动生成PDF翻译质量审计报告:从数据到可视化的完整方案
开发语言·python·ai·pdf·wpf
深念Y1 小时前
Makefile vs go run:Go 项目构建方式对比
java·开发语言·golang·k8s·编译·流水线·cicd