Main Content

fontsize

Figure 内のオブジェクトのフォント サイズの変更

R2022a 以降

    説明

    fontsize(size,units) は、現在の Figure 内のすべてのテキストのフォント サイズとフォントの単位を設定します。UI コンポーネントや凡例が含まれている axes オブジェクトなど、他のグラフィックス オブジェクトが Figure に含まれている場合、fontsize は Figure 内のそのオブジェクトのフォント サイズおよびフォントの単位も設定します。フォントの単位は、"points""pixels""inches"、または "centimeters" にすることができます。

    R2023a より前: fontsize(obj,size,units) のように、すべての構文で最初の入力としてグラフィックス オブジェクトが必要です。

    fontsize("increase") は、フォント サイズを 1.1 倍大きくします。

    fontsize("decrease") は、フォント サイズを 0.9 倍小さくします。

    fontsize(scale=sfactor) は、フォント サイズを sfactor 倍拡大/縮小します。たとえば、スケール係数 1.2 を使用すると、120% に拡大します。

    fontsize("default") は、フォント サイズおよびフォントの単位を既定の自動値にリセットします。

    fontsize(obj,___) は、グラフィックス オブジェクト obj 内のすべてのテキストのフォント サイズを設定します。他のグラフィックス オブジェクトが obj に含まれている場合、fontsize はそのオブジェクトのフォント サイズも設定します。前述の任意の構文で最初の入力引数として obj を指定します。

    すべて折りたたむ

    タイトルと凡例をもつ 2 つのラインを含むプロットを作成します。

    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.

    フォント サイズを 16 ポイントに増やします。

    fontsize(16,"points")

    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 より前: 関数 fontsize の最初の引数として gcf を指定します。たとえば、fontsize(gcf,16,"points") のようにします。

    フォント サイズが異なる複数のテキスト要素を使用してプロットを作成します。

    [X,Y,Z] = peaks;
    contourf(X,Y,Z,LineColor="#4F4F4F")
    title("Peak Elevation")
    colorbar
    annotation("textarrow",[.53 .41],[.65 .47],String="Local maxima")
    annotation("textarrow",[.53 .59],[.65 .55])

    Figure contains an axes object. The axes object with title Peak Elevation contains an object of type contour.

    スケール係数 1.2 を使用して Figure 内のフォント サイズを 120% に拡大します。関数 fontsize では、各フォント サイズが個別に拡大/縮小されるため、各フォントの相対サイズが維持されます。

    fontsize(gcf,scale=1.2)

    Figure contains an axes object. The axes object with title Peak Elevation contains an object of type contour.

    関数 tiledlayout および nexttile を使用して、複数のプロットのタイルを作成します。

    x = linspace(0,3*pi,200);
    y = cos(x) + rand(1,200);
    t = tiledlayout(2,2);
    
    % Top scatter plot in tiles 1,2
    ax1 = nexttile([1 2]);
    scatter(x,y)
    title("Random Variance on Cosine")
    
    % Lower polar plot in tile 3
    ax2 = nexttile;
    plot(x,cos(x)+0.5)
    
    % Lower histogram in tile 4
    ax3 = nexttile;
    histogram(y,20)

    Figure contains 3 axes objects. Axes object 1 with title Random Variance on Cosine contains an object of type scatter. Axes object 2 contains an object of type line. Axes object 3 contains an object of type histogram.

    散布図のフォント サイズを拡大し、他の 2 つのプロットのフォント サイズを 10 ピクセルに変更します。

    fontsize(ax1,scale=1.2)
    fontsize([ax2 ax3],10,"pixels")

    Figure contains 3 axes objects. Axes object 1 with title Random Variance on Cosine contains an object of type scatter. Axes object 2 contains an object of type line. Axes object 3 contains an object of type histogram.

    すべてのタイル表示プロットでフォント サイズの変更を元に戻すには、フォント サイズおよび単位を既定値にリセットします。gcf で返された現在の figure オブジェクトを使用して、3 つのプロットすべてにこの変更を適用します。

    fontsize(gcf,"default")

    Figure contains 3 axes objects. Axes object 1 with title Random Variance on Cosine contains an object of type scatter. Axes object 2 contains an object of type line. Axes object 3 contains an object of type histogram.

    以下の関数ファイルを作成し、MATLAB® パス上に myapplayout.m として保存します。この関数は、簡単なアプリで各種プロット タイプを使用してデータをプロットするためのレイアウトを返します。

    function fig = myapplayout
    % Create figure window
    fig = uifigure;
    
    % Create UI components
    ax = uiaxes(fig,Position=[15 70 535 340]);
    lbl = uilabel(fig,Position=[30 15 100 35],Text="Choose Plot Type:");
    b1 = uibutton(fig,Position=[140 15 180 35],Text="Surf");
    b2 = uibutton(fig,Position=[350 15 180 35],Text="Mesh");
    
    % Configure UI component appearance
    surf(ax,peaks);
    fontsize(fig,8,"pixels")
    title(ax,"Peak Surface",FontSize=11)
    end
    

    関数を呼び出し、返された figure オブジェクトを f に代入します。

    f = myapplayout;

    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 を使用して、figure 内のすべてのテキストのフォント サイズを読みやすくなるまで大きくします。ここでは、関数 fontsize によって各フォント サイズが個別に 1.1 倍拡大され、各フォントの相対サイズが維持されます。

    fontsize(f,"increase")
    fontsize(f,"increase")
    fontsize(f,"increase")

    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.

    入力引数

    すべて折りたたむ

    フォント サイズ。正のスカラー値として指定します。

    データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    フォント サイズの単位。"points""pixels""inches"、または "centimeters" として指定します。

    スケール係数。スカラーとして指定します。ターゲット オブジェクトの下にあるすべてのフォント サイズは、sfactor 倍拡大/縮小されます。フォント サイズを大きくする場合は 1 より大きいスケール係数を使用し、フォント サイズを小さくする場合は 1 より小さい係数を使用します。

    例: fontsize(gcf,scale=0.8) の場合、テキストは元のサイズの 80% に縮小されます。

    データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    テキストが含まれたオブジェクトまたはコンテナー。グラフィックス オブジェクトまたはグラフィックス オブジェクトの配列として指定します。関数 fontsize は、指定したオブジェクト内のテキストのフォント サイズを設定します。UI コンポーネントが含まれている Figure や凡例が含まれている axes オブジェクトなど、他のグラフィックス オブジェクトが obj に含まれている場合、関数は obj 内のそのオブジェクトのフォント サイズおよびフォントの単位も設定します。FontSize プロパティが指定されていないオブジェクトは影響を受けません。

    バージョン履歴

    R2022a で導入

    すべて展開する