Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

tiledlayout

タイル表示チャート レイアウトの作成

R2019b 以降. 次よりも推奨: subplot.

説明

tiledlayout(m,n) は、現在の Figure に複数のプロットを表示するためのタイル表示チャート レイアウトを作成します。このレイアウトは、固定の mn 列のタイル配置をもち、最大 m*n 個のプロットを表示できます。Figure がない場合、MATLAB® は Figure を作成し、レイアウトをその中に配置します。現在の Figure に既に座標軸またはレイアウトが含まれている場合、MATLAB は、その座標軸またはレイアウトを新しいレイアウトに置き換えます。

タイル表示チャート レイアウトには、Figure または親コンテナー全体をカバーする非表示のタイルのグリッドが含まれています。それぞれのタイルに、プロットを表示するための座標軸を含めることができます。レイアウトを作成した後、関数 nexttile を呼び出して axes オブジェクトをレイアウト内に配置します。次に、プロット関数を呼び出して、座標軸にプロットします。

tiledlayout(arrangement) は、座標軸の任意の数値を保持できるレイアウトを作成します。当初は、レイアウト全体を埋める空のタイルが 1 つのみあります。後続の座標軸の配置を制御する配置の値を指定します。

  • "flow" — Figure のサイズおよび座標軸の数に応じてリフローできる、座標軸のグリッドのレイアウトを作成します。

  • "vertical" — 座標軸の垂直スタックのレイアウトを作成します。 (R2023a 以降)

  • "horizontal" — 座標軸の水平スタックのレイアウトを作成します。 (R2023a 以降)

引数 arrangement はかっこなしで指定できます。たとえば、tiledlayout vertical の場合、座標軸の垂直スタックのレイアウトを作成します。

tiledlayout(___,Name,Value) は、1 つ以上の名前と値のペアの引数を使用して、レイアウトの追加のオプションを指定します。オプションは他のすべての入力引数の後に指定します。たとえば、tiledlayout(2,2,"TileSpacing","compact") は、タイルの間隔を最小にして 2 行 2 列のレイアウトを作成します。プロパティの一覧については、TiledChartLayout のプロパティ を参照してください。

tiledlayout(parent,___) は、現在の Figure ではなく指定した親コンテナーにレイアウトを作成します。親コンテナーを、その他すべての入力引数の前に指定します。

t = tiledlayout(___) は、TiledChartLayout オブジェクトを返します。レイアウトの作成後にプロパティを設定するには、t を使用します。

すべて折りたたむ

22 列のタイル表示チャート レイアウトを作成し、関数 peaks を呼び出して事前定義された表面の座標を取得します。関数 nexttile を呼び出して、最初のタイルに axes オブジェクトを作成します。次に、関数 surf を呼び出して座標軸にプロットします。他の 3 つのタイルでは、異なるプロット関数を使用してこの処理を繰り返します。

tiledlayout(2,2);
[X,Y,Z] = peaks(20);

% Tile 1
nexttile
surf(X,Y,Z)

% Tile 2
nexttile
contour(X,Y,Z)

% Tile 3
nexttile
imagesc(Z)

% Tile 4
nexttile
plot3(X,Y,Z)

Figure contains 4 axes objects. Axes object 1 contains an object of type surface. Axes object 2 contains an object of type contour. Axes object 3 contains an object of type image. Axes object 4 contains 20 objects of type line.

4 つの座標ベクトル、xy1y2 および y3 を作成します。引数 'flow' を指定して関数 tiledlayout を呼び出すことで、任意の数の座標軸を収められるタイル表示チャート レイアウトを作成します。関数 nexttile を呼び出して、最初の座標軸を作成します。次に、最初のタイルに y1 をプロットします。この最初のプロットで、レイアウト全体が埋まります。

x = linspace(0,30);
y1 = sin(x/2);
y2 = sin(x/3);
y3 = sin(x/4);

% Plot into first tile three times
tiledlayout('flow')
nexttile
plot(x,y1)

Figure contains an axes object. The axes object contains an object of type line.

2 番目のタイルと座標軸を作成し、座標軸にプロットします。

nexttile
plot(x,y2)

Figure contains 2 axes objects. Axes object 1 contains an object of type line. Axes object 2 contains an object of type line.

この処理を繰り返して、3 番目のプロットを作成します。

nexttile
plot(x,y3)

Figure contains 3 axes objects. Axes object 1 contains an object of type line. Axes object 2 contains an object of type line. Axes object 3 contains an object of type line.

この処理を繰り返して、4 番目のプロットを作成します。ここでは、y1 をプロットした後で hold on を呼び出して、同じ座標軸に 3 本のラインをすべてプロットします。

nexttile
plot(x,y1)
hold on
plot(x,y2)
plot(x,y3)
hold off

Figure contains 4 axes objects. Axes object 1 contains an object of type line. Axes object 2 contains an object of type line. Axes object 3 contains an object of type line. Axes object 4 contains 3 objects of type line.

関数 tiledlayout を呼び出すときに "vertical" オプションを指定することで、プロットの垂直スタックをもつタイル表示チャート レイアウトを作成します。次に、関数 nexttile を呼び出してからプロット関数を呼び出して、3 つのプロットを作成します。nexttile を呼び出すごとに、新しい axes オブジェクトがスタックの下に追加されます。

tiledlayout("vertical")
x = 0:0.1:5;
nexttile
plot(x,sin(x))
nexttile
plot(x,sin(x+1))
nexttile
plot(x,sin(x+2))

Figure contains 3 axes objects. Axes object 1 contains an object of type line. Axes object 2 contains an object of type line. Axes object 3 contains an object of type line.

関数 tiledlayout を呼び出すときに "horizontal" オプションを指定することで、プロットの水平スタックをもつタイル表示チャート レイアウトを作成します。次に、関数 nexttile を呼び出してからプロット関数を呼び出して、3 つのプロットを作成します。nexttile を呼び出すごとに、新しい axes オブジェクトがスタックの右側に追加されます。

tiledlayout("horizontal")
x = 0:0.1:10;
nexttile
plot(x,sin(x/2))
nexttile
plot(x,sin(x))
nexttile
plot(x,sin(2*x))

Figure contains 3 axes objects. Axes object 1 contains an object of type line. Axes object 2 contains an object of type line. Axes object 3 contains an object of type line.

5 つの座標ベクトル、xy1y2y3 および y4 を作成します。次に、関数 tiledlayout を呼び出して 22 列のレイアウトを作成し、TileChartLayout オブジェクトを格納するための戻り引数を指定します。関数 nexttile を呼び出して次の空のタイルに axes オブジェクトを作成してから、関数 plot を呼び出します。

x = linspace(0,30);
y1 = sin(x);
y2 = sin(x/2);
y3 = sin(x/3);
y4 = sin(x/4);
t = tiledlayout(2,2);

% Tile 1
nexttile
plot(x,y1)

% Tile 2
nexttile
plot(x,y2)

% Tile 3
nexttile
plot(x,y3)

% Tile 4
nexttile
plot(x,y4)

Figure contains 4 axes objects. Axes object 1 contains an object of type line. Axes object 2 contains an object of type line. Axes object 3 contains an object of type line. Axes object 4 contains an object of type line.

TileSpacing プロパティを 'compact' に設定して、タイルの間隔を狭くします。次に、Padding プロパティを 'compact' に設定して、レイアウトの端と Figure の端の間隔を狭くします。

t.TileSpacing = 'compact';
t.Padding = 'compact';

Figure contains 4 axes objects. Axes object 1 contains an object of type line. Axes object 2 contains an object of type line. Axes object 3 contains an object of type line. Axes object 4 contains an object of type line.

22 列のタイル表示チャート レイアウト t を作成します。名前と値のペアの引数 TileSpacing を指定して、タイルの間隔を最小にします。次に、各タイルにタイトル付きのプロットを作成します。

t = tiledlayout(2,2,'TileSpacing','Compact');

% Tile 1
nexttile
plot(rand(1,20))
title('Sample 1')

% Tile 2
nexttile
plot(rand(1,20))
title('Sample 2')

% Tile 3
nexttile
plot(rand(1,20))
title('Sample 3')

% Tile 4
nexttile
plot(rand(1,20))
title('Sample 4')

Figure contains 4 axes objects. Axes object 1 with title Sample 1 contains an object of type line. Axes object 2 with title Sample 2 contains an object of type line. Axes object 3 with title Sample 3 contains an object of type line. Axes object 4 with title Sample 4 contains an object of type line.

共有タイトルと共有軸ラベルを表示するには、関数 titlexlabel、および ylabelt を渡します。

title(t,'Size vs. Distance')
xlabel(t,'Distance (mm)')
ylabel(t,'Size (mm)')

Figure contains 4 axes objects. Axes object 1 with title Sample 1 contains an object of type line. Axes object 2 with title Sample 2 contains an object of type line. Axes object 3 with title Sample 3 contains an object of type line. Axes object 4 with title Sample 4 contains an object of type line.

Figure 内にパネルを作成します。次に、関数 tiledlayout の最初の引数として panel オブジェクトを指定することで、パネル内にタイル表示チャート レイアウトを作成します。各タイルにプロットを表示します。

p = uipanel('Position',[.1 .2 .8 .6]);
t = tiledlayout(p,2,1);

% Tile 1
nexttile(t)
stem(1:13)

% Tile 2
nexttile(t)
bar([10 22 31 43 52])

Figure contains 2 axes objects and another object of type uipanel. Axes object 1 contains an object of type stem. Axes object 2 contains an object of type bar.

関数 tiledlayout を呼び出して、21 列のタイル表示チャート レイアウトを作成します。出力引数を指定して関数 nexttile を呼び出し、座標軸を保存します。次に座標軸にプロットし、x 軸と y 軸の色を赤に設定します。2 番目のタイルでこの処理を繰り返します。

t = tiledlayout(2,1);

% First tile
ax1 = nexttile;
plot([1 2 3 4 5],[11 6 10 4 18]);
ax1.XColor = [1 0 0];
ax1.YColor = [1 0 0];

% Second tile
ax2 = nexttile;
plot([1 2 3 4 5],[5 1 12 9 2],'o');
ax2.XColor = [1 0 0];
ax2.YColor = [1 0 0];

Figure contains 2 axes objects. Axes object 1 contains an object of type line. Axes object 2 contains a line object which displays its values using only markers.

ボウリング リーグの 4 ゲームにわたるデータを格納したベクトルとして、scoresstrikes を定義します。次にタイル表示チャート レイアウトを作成し、各チームのストライクの数を示す 3 つのプロットを表示します。

scores = [444 460 380 
          387 366 500 
          365 451 611 
          548 412 452];

strikes = [9  6  5  
           6  4  8 
           4  7  16  
           10 9  8];
     
t = tiledlayout('flow');

% Team 1
nexttile
plot([1 2 3 4],strikes(:,1),'-o')
title('Team 1 Strikes')

% Team 2
nexttile
plot([1 2 3 4],strikes(:,2),'-o')
title('Team 2 Strikes')

% Team 3
nexttile
plot([1 2 3 4],strikes(:,3),'-o')
title('Team 3 Strikes')

Figure contains 3 axes objects. Axes object 1 with title Team 1 Strikes contains an object of type line. Axes object 2 with title Team 2 Strikes contains an object of type line. Axes object 3 with title Team 3 Strikes contains an object of type line.

関数 nexttile を呼び出し、2 行 3 列にわたる axes オブジェクトを作成します。その後、座標軸に棒グラフを凡例付きで表示し、座標軸の目盛りの値とラベルを設定します。関数 title を呼び出し、タイルをレイアウトに追加します。

nexttile([2 3]);
bar([1 2 3 4],scores)
legend('Team 1','Team 2','Team 3','Location','northwest')

% Configure ticks and axis labels
xticks([1 2 3 4])
xlabel('Game')
ylabel('Score')

% Add layout title
title(t,'April Bowling League Data')

Figure contains 4 axes objects. Axes object 1 with title Team 1 Strikes contains an object of type line. Axes object 2 with title Team 2 Strikes contains an object of type line. Axes object 3 with title Team 3 Strikes contains an object of type line. Axes object 4 with xlabel Game, ylabel Score contains 3 objects of type bar. These objects represent Team 1, Team 2, Team 3.

特定の位置から axes オブジェクトの範囲を設定するには、タイル番号と範囲の値を指定します。

ボウリング リーグの 4 ゲームにわたるデータを格納したベクトルとして、scoresstrikes を定義します。次に 33 列のタイル表示チャート レイアウトを作成し、各チームのストライクの数を示す 5 つの棒グラフを表示します。

scores = [444 460 380 388 389
          387 366 500 467 460
          365 451 611 426 495
          548 412 452 471 402];

strikes = [9  6  5  7  5
           6  4  8 10  7
           4  7 16  9  9
           10  9  8  8  9];
       
t = tiledlayout(3,3);

% Team 1
nexttile
bar([1 2 3 4],strikes(:,1))
title('Team 1 Strikes')

% Team 2
nexttile
bar([1 2 3 4],strikes(:,2))
title('Team 2 Strikes')

% Team 3
nexttile
bar([1 2 3 4],strikes(:,3))
title('Team 3 Strikes')

% Team 4
nexttile
bar([1 2 3 4],strikes(:,4))
title('Team 4 Strikes')

% Team 5
nexttile(7)
bar([1 2 3 4],strikes(:,5))
title('Team 5 Strikes')

Figure contains 5 axes objects. Axes object 1 with title Team 1 Strikes contains an object of type bar. Axes object 2 with title Team 2 Strikes contains an object of type bar. Axes object 3 with title Team 3 Strikes contains an object of type bar. Axes object 4 with title Team 4 Strikes contains an object of type bar. Axes object 5 with title Team 5 Strikes contains an object of type bar.

より大きいプロットを凡例付きで表示します。関数 nexttile を呼び出して、座標軸の左上隅を 5 番目のタイルに配置し、座標軸の範囲を 2 行 2 列のタイルに指定します。すべてのチームのスコアをプロットします。4 つの目盛りを表示し、各座標軸にラベルを追加するように x 軸を設定します。次に、レイアウトの上部に共有タイトルを追加します。

nexttile(5,[2 2]);
plot([1 2 3 4],scores,'-.')
labels = {'Team 1','Team 2','Team 3','Team 4','Team 5'};
legend(labels,'Location','northwest')

% Configure ticks and axis labels
xticks([1 2 3 4])
xlabel('Game')
ylabel('Score')

% Add layout title
title(t,'April Bowling League Data')

Figure contains 6 axes objects. Axes object 1 with title Team 1 Strikes contains an object of type bar. Axes object 2 with title Team 2 Strikes contains an object of type bar. Axes object 3 with title Team 3 Strikes contains an object of type bar. Axes object 4 with title Team 4 Strikes contains an object of type bar. Axes object 5 with title Team 5 Strikes contains an object of type bar. Axes object 6 with xlabel Game, ylabel Score contains 5 objects of type line. These objects represent Team 1, Team 2, Team 3, Team 4, Team 5.

1 行 2 列のタイル表示チャート レイアウトを作成します。最初のタイルに、マップ上の 2 つの都市を結ぶラインを含む地理プロットを表示します。2 番目のタイルに、極座標の散布図を作成します。

tiledlayout(1,2)

% Display geographic plot
nexttile
geoplot([47.62 61.20],[-122.33 -149.90],'g-*')

% Display polar plot
nexttile
theta = pi/4:pi/4:2*pi;
rho = [19 6 12 18 16 11 15 15];
polarscatter(theta,rho)

nexttile の出力引数が役に立つ場合の 1 つとして、前のタイルの内容を調整するときがあります。たとえば、前のプロットで使用されているカラーマップの再設定を決定することがあります。

2 行 2 列のタイル表示チャート レイアウトを作成します。関数 peaks を呼び出して、事前定義された表面の座標を取得します。次に、各タイルにそれぞれ異なる表面プロットを作成します。

tiledlayout(2,2);
[X,Y,Z] = peaks(20);

% Tile 1
nexttile
surf(X,Y,Z)

% Tile 2
nexttile
contour(X,Y,Z)

% Tile 3
nexttile
imagesc(Z)

% Tile 4
nexttile
plot3(X,Y,Z)

Figure contains 4 axes objects. Axes object 1 contains an object of type surface. Axes object 2 contains an object of type contour. Axes object 3 contains an object of type image. Axes object 4 contains 20 objects of type line.

3 番目のタイルのカラーマップを変更するには、そのタイルの座標軸を取得します。タイル番号を指定して関数 nexttile を呼び出し、座標軸の出力引数を返します。次に、座標軸を関数 colormap に渡します。

ax = nexttile(3);
colormap(ax,cool)

Figure contains 4 axes objects. Axes object 1 contains an object of type surface. Axes object 2 contains an object of type contour. Axes object 3 contains an object of type image. Axes object 4 contains 20 objects of type line.

それぞれのタイルに 2 つのプロットを含み、1 つのプロットが 2 行 2 列にわたる、2 行 3 列のタイル表示チャート レイアウトを作成します。

t = tiledlayout(2,3);
[X,Y,Z] = peaks;

% Tile 1
nexttile
contour(X,Y,Z)

% Span across two rows and columns
nexttile([2 2])
contourf(X,Y,Z)

% Last tile
nexttile
imagesc(Z)

Figure contains 3 axes objects. Axes object 1 contains an object of type contour. Axes object 2 contains an object of type contour. Axes object 3 contains an object of type image.

座標軸の範囲内のカラーマップを変更するには、座標軸の左上隅を含むようにタイルの位置を特定します。この場合、左上隅は 2 番目のタイル内にあります。タイルの位置として 2 を指定して関数 nexttile を呼び出し、出力引数を 1 つ指定してその位置にある axes オブジェクトを返します。次に、座標軸を関数 colormap に渡します。

ax = nexttile(2);
colormap(ax,hot)

Figure contains 3 axes objects. Axes object 1 contains an object of type contour. Axes object 2 contains an object of type contour. Axes object 3 contains an object of type image.

patients データ セットを読み込み、変数のサブセットから table を作成します。次に、22 列のタイル表示チャート レイアウトを作成します。最初のタイルに散布図、2 番目のタイルにヒートマップ、そして下の 2 つのタイルにわたって積み上げプロットを表示します。

load patients
tbl = table(Diastolic,Smoker,Systolic,Height,Weight,SelfAssessedHealthStatus);
tiledlayout(2,2)

% Scatter plot
nexttile
scatter(tbl.Height,tbl.Weight)

% Heatmap
nexttile
heatmap(tbl,'Smoker','SelfAssessedHealthStatus','Title','Smoker''s Health');

% Stacked plot
nexttile([1 2])
stackedplot(tbl,{'Systolic','Diastolic'});

Figure contains an axes object and other objects of type . The axes object contains an object of type scatter. The chart of type heatmap has title Smoker's Health.

nexttile を呼び出し、タイル番号を 1 に指定して、そのタイル内の座標軸を現在の座標軸にします。そのタイルの内容をヒストグラム付き散布図に置き換えます。

nexttile(1)
scatterhistogram(tbl,'Height','Weight');

Figure contains objects of type . The chart of type heatmap has title Smoker's Health.

カラー バーまたは凡例を 2 つ以上のプロットで共有する場合、それを個別のタイルに配置できます。

タイル表示チャート レイアウトで peaksmembrane のデータ セットの塗りつぶし等高線図を作成します。

Z1 = peaks;
Z2 = membrane;
tiledlayout(2,1);
nexttile
contourf(Z1)
nexttile
contourf(Z2)

Figure contains 2 axes objects. Axes object 1 contains an object of type contour. Axes object 2 contains an object of type contour.

カラー バーを追加し、east タイルに移動します。

cb = colorbar;
cb.Layout.Tile = 'east';

Figure contains 2 axes objects. Axes object 1 contains an object of type contour. Axes object 2 contains an object of type contour.

場合によっては、座標軸関数 (axespolaraxesgeoaxes) のいずれかを呼び出して、座標軸を作成しなければならないことがあります。これらの関数のいずれかを使用して座標軸を作成するときに、引数 parent をタイル表示チャート レイアウトとして指定します。次に、座標軸の Layout プロパティを設定して、座標軸を配置します。

タイル表示チャート レイアウト t を作成し、'flow' タイル配置を指定します。最初から 3 つのタイルのそれぞれに、プロットを表示します。

t = tiledlayout('flow');
nexttile
plot(rand(1,10));
nexttile
plot(rand(1,10));
nexttile
plot(rand(1,10));

関数 geoaxes を呼び出し、引数 parent として t を指定することで、geographic axes オブジェクト gax を作成します。既定で、座標軸は最初のタイルに入るため、gax.Layout.Tile4 に設定して座標軸を 4 番目のタイルに移動します。gax.Layout.TileSpan[2 3] に設定して、座標軸の範囲を 23 列のタイル領域に設定します。

gax = geoaxes(t);
gax.Layout.Tile = 4;
gax.Layout.TileSpan = [2 3];

関数 geoplot を呼び出します。次に、座標軸について、マップの中央とズーム レベルを設定します。

geoplot(gax,[47.62 61.20],[-122.33 -149.90],'g-*')
gax.MapCenter = [47.62 -122.33];
gax.ZoomLevel = 2;

入力引数

すべて折りたたむ

行数。正の整数として指定します。

例: tiledlayout(2,3) は、2 行 3 列のタイルからなるタイル表示チャート レイアウトを作成します。

列数。正の整数として指定します。

例: tiledlayout(2,3) は、2 行 3 列のタイルからなるタイル表示チャート レイアウトを作成します。

タイル配置。次の値のいずれかとして指定します。

  • "flow" — 座標軸のグリッドのレイアウトを作成します。nexttile を呼び出すたびに、すべての座標軸の縦横比を約 4:3 に維持しながら、新しい座標軸が収まるようにレイアウトが必要に応じてリフローします。

  • "vertical" — 座標軸の垂直スタックのレイアウトを作成します。nexttile を呼び出すごとに、新しい axes オブジェクトがスタックの下に追加されます。 (R2023a 以降)

  • "horizontal" — 座標軸の水平スタックのレイアウトを作成します。nexttile を呼び出すごとに、新しい axes オブジェクトがスタックの右側に追加されます。 (R2023a 以降)

例: tiledlayout("vertical") では座標軸の垂直スタックのレイアウトを作成します。

親コンテナー。FigurePanelTab、または TiledChartLayout オブジェクトとして指定します。

名前と値の引数

引数のオプションのペアを Name1=Value1,...,NameN=ValueN として指定します。ここで Name は引数名で、Value は対応する値です。名前と値の引数は他の引数の後になければなりませんが、ペアの順序は重要ではありません。

R2021a より前では、コンマを使用してそれぞれの名前と値を区切り、Name を引用符で囲みます。

例: tiledlayout(2,2,"TileSpacing","compact") は、タイルの間隔を最小にして 2 行 2 列のレイアウトを作成します。

メモ

ここでは、プロパティの一部だけを紹介しています。完全な一覧については、TiledChartLayout のプロパティ を参照してください。

タイルの間隔。"loose""compact""tight"、または "none" として指定します。このプロパティを使用して、タイルの間隔を制御します。

次の表に、それぞれの値が 22 列のレイアウトの外観にどのような影響を与えるかを示します。

外観

"loose"

Tiled chart layout with "loose" tile spacing.

"compact"

Tiled chart layout with "compact" tile spacing.

"tight"

Tiled chart layout with "tight" tile spacing.

"none"

Tiled chart layout with "none" tile spacing.

レイアウトの周囲のパディング。"loose""compact" または "tight" として指定します。このプロパティの値にかかわらず、このレイアウトには軸ラベルなどのすべての装飾にそのためのスペースがあります。

次の表に、それぞれの値が 22 列のレイアウトの外観にどのような影響を与えるかを示します。

外観

"loose"

Tiled chart layout with "loose" padding.

"compact"

Tiled chart layout with "compact" padding.

"tight"

Tiled chart layout with "tight" padding.

バージョン履歴

R2019b で導入

すべて展開する