Matlab中设置字体

时间:2024-10-18 11:52:51

1、首先,我们在使用matlab画图时,其默认的字体为“Helvetica”。我们可以通过查看坐标轴属性看到字体情况。

Matlab中设置字体

2、如果要修改字体,我们可以先选中坐标轴,然后右键点击坐标轴,选择“字体”。然后可以选择自己所需的字体。

Matlab中设置字体

3、我们这里介绍使用Matlab命令设置字体。如果单纯的使用plot,就是用默认字体,如:aa = randn(100,1);plot(aa);

Matlab中设置字体

4、我们可以在后面添加命令:set(gca,'FontSize',16);set(gca,'FontName','Times New Roman');legend('Randn Data');%gca代表内部坐标轴的属性;我们看到坐标轴包括图例的字体都已经为修改后的字体。

Matlab中设置字体

5、当然也可以自己设置图例的字体:把上述命令修改为:set(gca,'FontSize',16);set(gca,'FontName','Times New Roman');legend({'Randn Data'},'FontSize',26,... 'FontName','宋体');可以看到图例字体已修改为宋体。

Matlab中设置字体

6、当然,有时候也会在图形中加入text,如:set(gca,'FontSize',16);set(gca,'FontName','Times New Roman');legend('Randn Data');text(10,-2.5,['randn data']);但是text的字体是Matlab默认的“Helvetica”。

Matlab中设置字体

7、只能通过在相同行中加入设置的命令:set(gca,'FontSize',16);set(gca,'FontName','Times New Roman');legend('Randn Data');text(10,-2.5,['randn data']);text(10,-1.5,['randn data'],... 'FontSize',16,... 'FontName','Times New Roman');

Matlab中设置字体

8、有的时候,为了图省事,也可以一次性将图中的字体设置好,但是加入的text仍是Matlab默认字体,仍需自行设置。legend('Randn Data');text(10,-2.5,['randn data']);% text(10,-1.5,['randn data'],...% 'FontSize',16,...% 'FontName','Times New Roman');set(gca,'FontSize',16);set(gca,'FontName','Times New Roman');

Matlab中设置字体
© 手抄报圈