Main Content

缩小图形标题

MATLAB® 图形标题使用加粗的微大字体,以便更醒目。因此,图窗窗口中可能无法容纳长标题。例如,此代码创建一个绘图,其中的长标题无法容纳在图窗窗口范围内。

plot(1:10);
title(['This is a title that is too long and does not fit', ...
    'within the extents of the figure window.'])

Plot with a title that does not fit within the extents of the figure window

标题字体大小取决于坐标区的 TitleFontSizeMultiplierFontSize 属性。默认情况下,FontSize 属性为 10 磅,而 TitleFontSizeMultiplier1.100,这意味着标题字体大小为 11 磅。

若要更改标题字体大小而不影响坐标区的其他部分文本,请设置坐标区的 TitleFontSizeMultiplier 属性。例如,更改标题字体大小以匹配坐标区中的其他文本。

plot(1:10);
title(['This is a title that is too long and does not fit', ...
    'within the extents of the figure window.'])
ax = gca;
ax.TitleFontSizeMultiplier = 1;

Plot with a title whose font is the same size as other text in the axes

若要使整个坐标区的字体变小,请设置 FontSize 属性。更改此属性会影响标题、刻度标签和坐标轴标签(如果存在)的字体。

plot(1:10);
title(['This is a title that is too long and does not fit', ...
    'within the extents of the figure window.'])
ax = gca;
ax.FontSize = 8;

Plot with all fonts set to eight-point size

若要跨两行显示标题,请使用带有花括号 {} 的元胞数组定义多行标题。

plot(1:10);
title({'This is a title that is too long and does not fit', ...
    'within the extents of the figure window.'})

Plot with a title that is displayed across two lines

另请参阅

函数

属性