主要内容

fontname

更改图窗中对象的字体名称

自 R2022a 起

    说明

    fontname(fname) 将当前图窗中所有文本的字体名称设置为 fname。如果图窗包含其他图形对象,如 UI 组件或具有图例的坐标区对象,则 fontname 还会为图窗中的这些对象设置字体名称。使用 listfonts 查看可用的系统字体列表。

    在 R2023a 之前的版本中: 所有语法都需要使用图形对象作为第一个输入,例如 fontname(obj,fname)

    示例

    fontname("default") 将字体名称重置为默认自动字体名称。

    示例

    fontname(obj,___) 设置图形对象 obj 中所有文本的字体名称。如果 obj 包含其他图形对象,fontname 还会为这些对象设置字体名称。指定 obj 作为上述任何语法中的第一个输入参量。

    示例

    示例

    全部折叠

    创建一个绘图,其中包含两个线条以及标题和图例。

    plot([0 1; 1 2])
    title("Two Very Straight Lines")
    legend("Blue Line","Red Line")

    Figure contains an axes object. The axes object with title Two Very Straight Lines contains 2 objects of type line. These objects represent Blue Line, Red Line.

    将字体改成 Courier。

    fontname("courier")

    Figure contains an axes object. The axes object with title Two Very Straight Lines contains 2 objects of type line. These objects represent Blue Line, Red Line.

    在 R2023a 之前:将 gcf 指定为 fontname 函数的第一个参量。例如,fontname(gcf,"courier")

    创建以下函数文件,并将其保存为 MATLAB® 路径上的 plotapplayout.m。此函数返回一个简单 App 的布局,以使用不同绘图类型绘制数据。

    function fig = plotapplayout
    % Create figure window
    fig = uifigure;
    
    % Create UI components
    ax = uiaxes(fig,Position=[15 70 535 340]);
    lbl = uilabel(fig,Position=[30 15 110 35],Text="Plot Type:");
    b1 = uibutton(fig,Position=[150 15 180 35],Text="Surf");
    b2 = uibutton(fig,Position=[350 15 180 35],Text="Mesh");
    
    % Configure UI component appearance
    surf(ax,peaks);
    title(ax,"Peak Surface")
    fontname(fig,"Times")
    end
    

    调用该函数并将返回的图窗对象赋给 f

    f = plotapplayout;

    Figure contains an axes object and other objects of type uilabel, uibutton. The axes object with title Peak Surface contains an object of type surface.

    使用 f 将图窗中所有文本的字体更改为默认系统字体。

    fontname(f,"default")

    Figure contains an axes object and other objects of type uilabel, uibutton. The axes object with title Peak Surface contains an object of type surface.

    输入参数

    全部折叠

    字体名称,指定为字符向量或字符串标量。使用 listfonts 查看可用的系统字体列表。

    具有文本的对象或容器,指定为图形对象或由图形对象组成的数组。fontname 函数影响指定对象中的文本。如果 obj 包含其他图形对象,例如包含 UI 组件的图窗或具有图例的坐标区对象,则该函数还会为 obj 内的这些对象设置字体名称。

    版本历史记录

    在 R2022a 中推出

    全部展开