添加图标题、轴标签、图例、更改字体大小

添加图标题、轴标签、图例、更改字体大小

1 添加标题

title​:向图中添加标题

示例:

1
2
3
4
5
6
7
8
clc;
clear;

% 绘制
x = linspace(0,2*pi);
y = sin(x) - tan(sin(x));
plot(x,y)
title('y = sin(x)-tan(sin(x))')

结果展示:

在这里插入图片描述

2 添加轴标签

xlabel​:x轴标签
ylabel​:y轴标签
zlabel​:z轴标签(plot3)

示例:

1
2
3
4
5
6
7
8
9
10
clc;
clear;

% 绘制
x = linspace(0,2*pi);
y = sin(x)-tan(sin(x));
plot(x,y)
title('y = sin(x) - tan(sin(x))')
xlabel('X(m)')
ylabel('Y(m)')

结果展示:

在这里插入图片描述

3 添加图例

legend​:按绘图顺序添加图例

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
clc;
clear;

% 绘制
x = linspace(0,2*pi);
y = sin(x)-tan(cos(x));

plot(x,sin(x))
hold on
plot(x,cos(x))
hold on
plot(x,tan(cos(x)))
hold on
plot(x,y)
hold off

title('添加图例')
xlabel('X(m)')
ylabel('Y(m)')
% 按绘图顺序添加图例
legend('y = sin(x)','y = cos(x)','y = tan((cos(x))','y = sin(x) - tan(cos(x))')

结果展示:

在这里插入图片描述

4 更改标题、标签、图例的字体大小

'FontSize'​ 字号属性

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
clc;
clear;

% 绘制
x = linspace(0,2*pi);
y = sin(x)-tan(cos(x));

plot(x,sin(x))
hold on
plot(x,cos(x))
hold on
plot(x,tan(cos(x)))
hold on
plot(x,y)
hold off

title('添加图例','FontSize',20)
xlabel('X/(m)','FontSize',15)
ylabel('Y/(m)','FontSize',10)
% 按绘图顺序添加图例
legend('y = sin(x)','y = cos(x)','y = tan((cos(x))','y = sin(x) - tan(cos(x))')

结果展示:

在这里插入图片描述


相关链接

https://ww2.mathworks.cn/help/matlab/creating_plots/add-title-axis-labels-and-legend-to-graph.html

作者

Shepherd

发布于

2024-12-28

更新于

2025-01-25

许可协议

评论