Main Content

nexttile

タイル表示チャート レイアウトでの座標軸の作成

R2019b 以降

説明

nexttile は axes オブジェクトを作成し、現在の Figure 内のタイル表示チャート レイアウトで次の空のタイルに配置します。現在の Figure にレイアウトがない場合、nexttile は新しいレイアウトを作成し、'flow' タイル配置を使用して設定します。作成された axes オブジェクトが現在の座標軸になるため、次のプロット コマンドでそこにプロットすることができます。

nexttile(span) は、レイアウトの中心にあるグリッドの、複数の行または列にわたる axes オブジェクトを作成します。span は、[r c] の形式のベクトルとして指定します。座標軸は、rc 列のタイルにわたります。座標軸の左上隅が、グリッド内の最初の空である rc 列の領域の左上隅に配置されます。

nexttile(tilelocation) は、現在の座標軸を、tilelocation で指定されたタイル内の座標軸またはスタンドアロンの可視化として割り当てます。通常、この構文は、既存の座標軸またはスタンドアロンの可視化を変更する場合に便利です。ただし、場合により、nexttile は新しい axes オブジェクトを作成します。

  • 指定したタイルが空の場合、nexttile はそのタイルに axes オブジェクトを作成します。

  • 指定したタイルに axes オブジェクトまたはスタンドアロンの可視化オブジェクトの一部が含まれているが、その左上隅は含まれていない場合、nexttile は既存のオブジェクトを置き換えます。たとえば、tilelocation が複数のタイルにわたる axes オブジェクトの中央を参照している場合、nexttile は指定したタイルの既存の axes オブジェクトを新しいオブジェクトに置き換えます。

nexttile(tilelocation,span) は、tilelocation で指定されたタイルから始まる複数の行または列にわたる axes オブジェクトを作成します。指定したタイルが座標軸またはスタンドアロンの可視化によって占有されている場合、nexttile はそのオブジェクトを現在の座標軸にするか、置き換えます。

  • 既存の axes オブジェクトまたはスタンドアロンの可視化オブジェクトが、引数 tilelocation および span で指定したタイルと同じ一連のタイルにわたっている場合、nexttile はそのオブジェクトを現在の座標軸にします。

  • 既存の axes オブジェクトまたはスタンドアロンの可視化オブジェクトが、引数 tilelocation および span で指定したタイルと異なる一連のタイルにわたっている場合、nexttile は、新しい tilelocation 値および span 値を使用して、既存のオブジェクトを新しい axes オブジェクトに置き換えます。

nexttile(t,___) は、t で指定されたタイル表示チャート レイアウトに作用します。t を、その他すべての入力引数の前に指定します。この構文は、複数のレイアウトで作業している場合、あるいはレイアウトが Figure ではなくパネルまたはタブ内にある場合に便利です。

ax = nexttile(___) は、axes オブジェクトを返します。ax を使用して、座標軸のプロパティを設定します。また、axes オブジェクトを操作する他のグラフィックス関数への入力引数として ax を渡すこともできます。たとえば、関数 colormap または colororder を呼び出して、座標軸のカラー スキームを変更することができます。

すべて折りたたむ

タイル表示チャート レイアウトがまだ存在しない場合、nexttile はそれを 1 つ作成します。

4 つの座標ベクトル、xy1y2 および y3 を作成します。

関数 nexttile を呼び出して、タイル表示チャート レイアウト、および最初のタイルの axes オブジェクトを作成します。次に、最初のタイルに y1 をプロットします。nexttile'flow' タイル配置を使用してレイアウトを作成するため、この最初のプロットはレイアウト全体を埋めます。

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

% Create layout and first plot
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 を呼び出して 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.

関数 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.

関数 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)

Figure contains 2 axes objects. Geoaxes object 1 contains an object of type line. Polaraxes object 2 contains an object of type scatter.

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.

Figure 内にパネルを作成します。次に、関数 tiledlayout の最初の引数として panel オブジェクトを指定することで、パネル内にタイル表示チャート レイアウト t を作成します。既定で、nexttile は Figure 内でレイアウトを探します。しかし、レイアウトは Figure ではなくパネル内にあるため、nexttile を呼び出すときに入力引数として t を指定しなければなりません。

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.

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

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

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

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.

関数 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];

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. Geoaxes object 4 is empty.

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

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

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. Geoaxes object 4 contains an object of type line.

入力引数

すべて折りたたむ

タイルの位置。表のいずれかの値を指定します。

次の例のラベル付き四角形は、既定の TileIndexing スキームを使用したレイアウトにおけるグリッド内のタイルと外側のタイルを示します。実際には、グリッドは非表示であり、座標軸が入力されるまで、外側のタイルは領域を占有しません。太い境界線の四角形は、各例で選択されたタイルです。

tilelocation説明
正の整数レイアウトの中心にあるグリッドのタイルの 1 つ。既定では、タイル番号は 1 から始まり、左から右、上から下に向かって増加します。

2 行 2 列のレイアウトを作成し、グリッド内で 3 番目のタイルを選択します。

tiledlayout(2,2)
nexttile(3)

Third tile highlighted in a 2-by-2 layout.

'north''south''east'、または 'west'グリッドの外側にあるタイルの 1 つ。

2 行 2 列のレイアウトを作成し、グリッドの右側にある east タイルを選択します。

tiledlayout(2,2)
nexttile('east')

East tile highlighted in a 2-by-2 layout.

メモ

指定したタイルが空の場合、nexttile はそのタイル内に axes オブジェクトを配置します。タイルに axes オブジェクトまたはスタンドアロンの可視化が含まれている場合、そのオブジェクトが現在の座標軸になり、次のプロット コマンドでそのタイル内にプロットできます。

タイルの範囲。[r c] の形式のベクトルとして指定します。ここで、rc は正の整数です。この引数を使用して、座標軸の範囲をレイアウト内の rc 列のタイルに指定します。

引数 tilelocation を指定せずに引数 span を指定した場合、nexttile は座標軸の左上隅を、レイアウト内にある最初の空である rc 列の領域の左上隅に配置します。

しかし、引数 tilelocation と引数 span の両方を指定した場合、nexttile は座標軸の左上隅を、tilelocation で指定されたタイルの左上隅に配置します。たとえば、この 34 列のレイアウトの右側にある大きな座標軸は、タイル数が 2、範囲が [2 3] です。

3-by-4 tiled chart layout with an L-shaped arrangement of six small tiles containing axes objects. Inside the angle of the L, one large tile containing an axes object. The L shape is three tiles tall and four tiles wide. The large axes is two tiles tall by three tiles wide.

座標軸の配置先の TiledChartLayout オブジェクト。この引数は、複数のレイアウトで作業している場合、あるいはレイアウトが Figure ではなくパネルまたはタブ内にある場合に便利です。t を指定しない場合、nexttile は現在の Figure 内でレイアウトを探します。

バージョン履歴

R2019b で導入