Main Content

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

軸の範囲の指定

座標軸に表示するデータの位置は、x 軸、y 軸、および z 軸の範囲を設定することで制御できます。また、x 軸と y 軸のライン表示の位置変更 (2 次元プロットのみ) や、各軸に沿った値の増加方向の反転が可能です。

軸の範囲の変更

ライン プロットを作成します。関数 xlim および関数 ylim を使用して軸の範囲を指定します。3 次元プロットの場合は、関数 zlim を使用します。関数に [min max] の形式の 2 要素ベクトルを渡します。

x = linspace(-10,10,200); 
y = sin(4*x)./exp(x);
plot(x,y)
xlim([0 10])
ylim([-0.4 0.8])

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

軸範囲の半自動設定の使用

x 軸の上限値を 0、y 軸の下限値を -1 に設定します。その他の範囲は MATLAB により選択されます。下限値および上限値を自動的に計算する場合は、それぞれ -inf または inf を使用します。

[X,Y,Z] = peaks;
surf(X,Y,Z)
xlabel('x-axis')
ylabel('y-axis')
xlim([-inf 0]) 
ylim([-1 inf])

Figure contains an axes object. The axes object with xlabel x-axis, ylabel y-axis contains an object of type surface.

既定の範囲に戻す

メッシュ プロットを作成し、軸の範囲を変更します。次に、既定の範囲に戻します。

[X,Y,Z] = peaks;
mesh(X,Y,Z)
xlim([-2 2])
ylim([-2 2])
zlim([-5 5])

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

xlim auto
ylim auto
zlim auto

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

軸の方向の反転

x 軸と y 軸の値が増加する方向は、Axes オブジェクトの XDir プロパティと YDir プロパティを設定することで制御します。これらのプロパティを 'reverse' または 'normal' (既定) のいずれかに設定します。Axes オブジェクトにアクセスするには、gca コマンドを使用します。

stem(1:10)
ax = gca;
ax.XDir = 'reverse';
ax.YDir = 'reverse';

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

原点を通る軸のラインの表示

既定では、x 軸と y 軸は座標軸の外側の境界に沿って表示されます。軸のラインの位置を変えて原点 (0,0) で交差させるには、Axes オブジェクトの XAxisLocation プロパティと YAxisLocation プロパティを設定します。XAxisLocation'top''bottom''origin' のいずれかに設定します。YAxisLocation'left''right''origin' のいずれかに設定します。これらのプロパティは 2 次元表示の座標軸にのみ適用されます。

x = linspace(-5,5);
y = sin(x);
plot(x,y)

ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';

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

座標軸のボックスの外枠を削除します。

box off

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

参考

関数

プロパティ

関連するトピック