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

您所在的位置:网站首页 vscode2022字体大小设置 MATLAB:添加图标题、轴标签、图例、更改字体大小

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

2023-07-18 09:17| 来源: 网络整理| 查看: 265

文章目录 1 添加标题2 添加轴标签 3 添加图例 4 更改标题、标签、图例的字体大小

1 添加标题

title:向图中添加标题

示例:

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)

示例:

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:按绘图顺序添加图例

示例:

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' 字号属性

示例:

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



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3