Main Content

linkaxes

複数の座標軸の範囲の同期

説明

linkaxes(ax) は、指定された座標軸のベクトルの範囲を同期します。範囲を同期すると、1 つのプロットまたは Figure 内でズームまたはパンを行ったり、同じ範囲のデータを他のプロットまたは Figure に表示したりできます。最初に linkaxes を呼び出すときに、この関数は指定されたすべての座標軸の現在の範囲を内包する新しい範囲を選択します。

linkaxes(ax,dimension) は指定された軸の次元について、座標軸の範囲を同期します。たとえば、linkaxes(ax,'x') は、x 軸の範囲のみを同期します。

すべて折りたたむ

関数 tiledlayout および nexttile を使用して、プロットをタイル表示します。

関数 tiledlayout を使用して、3 行 1 列のタイル表示チャート レイアウトを作成します。次に、関数 nexttile を使用して、axes オブジェクト ax1ax2ax3 を作成し、各座標軸にプロットします。

tiledlayout(3,1)

% First plot
ax1 = nexttile;
x1 = linspace(0,6);
y1 = sin(x1);
plot(x1,y1)

% Second plot
ax2 = nexttile;
x2 = linspace(0,10);
y2 = 2*sin(2*x2);
plot(x2,y2)

% Third plot
ax3 = nexttile;
x3 = linspace(0,12,200);
y3 = 4*sin(6*x3);
plot(x3,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.

各プロットの x 軸と y 軸の範囲を同期します。新しい軸の範囲に古い範囲が内包されていることに注意してください。

linkaxes([ax1 ax2 ax3],'xy')

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.

1 番目のプロットの x 軸の範囲を設定します。すべての座標軸がリンクされるため、2 番目と 3 番目のプロットの x 軸の範囲も変化します。

ax1.XLim = [0 4.5];

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.

プロットの 1 つに移動するかズームすると、他の 2 つのプロットに同じデータの範囲が表示されます。

リンクを削除するには、linkaxes([ax1 ax2 ax3],'off') を使用します。

関数 linkaxes を使用して、複数の axes オブジェクトの x 軸の範囲を同期および変更します。

関数 tiledlayout および nexttile を使用して、プロットをタイル表示します。関数 tiledlayout を使用して、2 行 1 列のタイル表示チャート レイアウトを作成します。次に、関数 nexttile を使用して、axes オブジェクト ax1 および ax2 を作成し、各座標軸にプロットします。

t = tiledlayout(2,1);

% First plot
ax1 = nexttile;
p1 = peaks;
surf(ax1,p1);
view(3)

% Second plot
ax2 = nexttile;
p2 = peaks(25);
mesh(ax2,p2)

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

2 つの axes オブジェクトの x 軸の範囲を同期します。新しくリンクされた axes オブジェクトの x 軸の範囲が更新され、すべてのデータが含まれるようになります。

linkaxes([ax1 ax2],'x');

リンクされたすべての axes オブジェクトの x 軸の範囲を更新するには、axes オブジェクトのうちどれか 1 つで x 軸の範囲を設定します。

ax1.XLim = [0 15];
ax2.XLim
ans = 1×2

     0    15

同期をオフにすると、リンクが削除されます。

linkaxes([ax1 ax2],'off');

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

タイム ゾーンが異なる datetime 値の 2 つのプロットを比較する場合は、いずれかのルーラーの ReferenceDate プロパティを設定して、両方のプロットが同じタイム ゾーンを表すようにします。

2021 年 1 月 1 日にロンドンとニューヨークで新年を祝ってお祭り騒ぎしている人々の数を比較する 2 つのプロットのタイル表示を作成します。まずは最初のタイルに London データをプロットします。既定では、プロットはデータのタイム ゾーンを使用します。

London = datetime(2021,1,1,0:17,0,0,"TimeZone","Europe/London");
y = (1./(1:18).^2) * 100000;
ax1 = nexttile;
semilogy(ax1,London,y)
grid on
title("New Year's Day Revelers in London")

Figure contains an axes object. The axes object with title New Year's Day Revelers in London contains an object of type line.

NY データをプロットします。この 2 番目のプロットはニューヨークのタイム ゾーンです。そのため、視覚的な確認では、同じ時点における 2 つの場所でのお祭り騒ぎしている人々の数を正確に比較できません。

NY = datetime(2021,1,1,0:17,0,0,"TimeZone","America/New_York");
ax2 = nexttile;
semilogy(ax2,NY,y)
grid on
title("New Year's Day Revelers in New York")

Figure contains 2 axes objects. Axes object 1 with title New Year's Day Revelers in London contains an object of type line. Axes object 2 with title New Year's Day Revelers in New York contains an object of type line.

x 軸の基準日を "Europe/London" のタイム ゾーンの datetime 値に設定することで、ニューヨークのプロットのタイム ゾーンを変更します。次に、2 つの座標軸をリンクします。結果として、両方のプロットで同じタイム ゾーンが表されるようになります。

ax2.XAxis.ReferenceDate = datetime(2022,1,1,"TimeZone","Europe/London");
linkaxes([ax1,ax2],"x")

Figure contains 2 axes objects. Axes object 1 with title New Year's Day Revelers in London contains an object of type line. Axes object 2 with title New Year's Day Revelers in New York contains an object of type line.

入力引数

すべて折りたたむ

ターゲット座標軸。Axes オブジェクトのベクトルとして指定します。

任意の数の Axes オブジェクトをリンクできます。たとえば、linkaxes([ax1 ax2 ax3]) は、ax1ax2 および ax3 をリンクします。linkaxes([ax1 ax2]) および linkaxes([ax2 ax3]) を個別に呼び出すと、ax1ax2 の間のリンクがキャンセルされます。

同期する軸の範囲。次の値のいずれかとして指定します。

  • 'xyz' — x 軸、y 軸、z 軸の範囲を同期する。

  • 'x' — x 軸の範囲のみを同期する。

  • 'y' — y 軸の範囲のみを同期する。

  • 'z' — z 軸の範囲のみを同期する。

  • 'xy' — x 軸と y の範囲のみを同期する。

  • 'xz' — x 軸と z の範囲のみを同期する。

  • 'yz' — y 軸と z の範囲のみを同期する。

  • 'off' — 同期をオフにする。

バージョン履歴

R2006a より前に導入

すべて展開する