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')
相关推荐
老赵的博客10 分钟前
c++ 杂记
开发语言·c++
jimmy.hua13 分钟前
[C++刷怪笼]:set/map--优质且易操作的容器
开发语言·c++
w2sfot1 小时前
Passing Arguments as an Object in JavaScript
开发语言·javascript·ecmascript
郝学胜-神的一滴2 小时前
避免使用非const全局变量:C++中的最佳实践 (C++ Core Guidelines)
开发语言·c++·程序人生
搞一搞汽车电子2 小时前
S32K3平台eMIOS 应用说明
开发语言·驱动开发·笔记·单片机·嵌入式硬件·汽车
星马梦缘2 小时前
Matlab机器人工具箱使用2 DH建模与加载模型
人工智能·matlab·机器人·仿真·dh参数法·改进dh参数法
总有刁民想爱朕ha2 小时前
车牌模拟生成器:Python3.8+Opencv代码实现与商业应用前景(C#、python 开发包SDK)
开发语言·python·数据挖掘
小菜全3 小时前
uniapp新增页面及跳转配置方法
开发语言·前端·javascript·vue.js·前端框架
人衣aoa3 小时前
Python编程基础(八) | 类
开发语言·python
晚云与城3 小时前
今日分享:C++ Stack和queue(栈与队列)
开发语言·c++