Main Content

xline

定数の x 値をもつ垂直線

説明

xline(x) は、現在の座標軸における 1 つ以上の x 座標の位置に垂直線を作成します。たとえば、xline(2)x=2 の位置にラインを作成します。

xline(x,LineSpec) はライン スタイル、ラインの色、またはその両方を指定します。たとえば、xline([12 20 33],'--b') は 3 本の青の破線を作成します。

xline(x,LineSpec,labels) はラインにラベルを追加します。

xline(___,Name,Value) は 1 つ以上の名前と値のペアの引数を使用して、定数直線のプロパティを指定します。プロパティの一覧については、ConstantLine のプロパティ を参照してください。名前と値のペアは他のすべての入力引数の後で指定します。

xline(ax,___) は、現在の座標軸ではなく、指定された座標軸にラインを作成します。

xl = xline(___)ConstantLine オブジェクトまたは ConstantLine オブジェクトの配列を返します。xl を使用して、ラインが作成された後にそのプロパティの変更やクエリを行います。

すべて折りたたむ

x = 3 の位置に垂直線を作成します。

xline(3);

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

ラベル付きのラインを作成するには、ライン スタイルも指定しなければなりません。既定のライン スタイルは実線 '-' です。

x = linspace(0,6,100);
y = exp(x);
plot(x,y)
xline(4.5,'-',{'Acceptable','Limit'});

Figure contains an axes object. The axes object contains 2 objects of type line, constantline.

正規分布する乱数のベクトルを作成し、そのヒストグラムを表示します。その後、平均値、平均よりも 1 標準偏差下、および平均よりも 1 標準偏差上の 3 つの位置にラベル付きの垂直線を作成します。

data = 5 * randn(1,500) + 20;
histogram(data,'FaceAlpha',0.1,'EdgeAlpha',0.1);
m = mean(data);
s = std(data);
xline([m-s m m+s],'-',{'-1 Standard Dev.','Average','+1 Standard Dev.'})

Figure contains an axes object. The axes object contains 4 objects of type histogram, constantline.

x = 5 の位置に赤い破線を作成します。

xline(5,'--r');

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

凡例のラベルと表示名の両方を使用して、垂直の一点鎖線を作成します。

y = [3187 2693 1771 1826 1958 3222 1645];
barh(y,'DisplayName','Daily Sales')
xl = xline(2328,'-.','Average','DisplayName','Average Sales');

Figure contains an axes object. The axes object contains 2 objects of type bar, constantline. These objects represent Daily Sales, Average Sales.

ラベルの垂直方向および水平方向の配置を調整してから、凡例を表示します。

xl.LabelVerticalAlignment = 'middle';
xl.LabelHorizontalAlignment = 'center';
legend('show');

Figure contains an axes object. The axes object contains 2 objects of type bar, constantline. These objects represent Daily Sales, Average Sales.

関数 tiledlayout を呼び出して、2 行 1 列のタイル表示チャート レイアウトを作成します。関数 nexttile を呼び出して、axes オブジェクト ax1 および ax2 を作成します。次に、各座標軸にプロットします。座標軸を関数 xline に引き渡すことで、垂直点線およびラベルを各プロットに追加します。

tiledlayout(2,1)
ax1 =nexttile;
x = linspace(0,10,200);
y1 = cos(x); 
plot(ax1,x,y1)

ax2 = nexttile;
y2 = sin(x); 
plot(ax2,x,y2)

xline(ax1,pi/2,':','cos(\pi/2)=0');
xline(ax2,pi,':','sin(\pi)=0');

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

入力引数

すべて折りたたむ

x 座標。数値、categorical 値、datetime 値、または duration 値を含むスカラーまたはベクトルとして指定します。x のデータ型は x 軸のデータ型と一致しなければなりません。

例: xline(10)x=10 の位置にラインを表示します。

例: xline([13 20 33])x=13x=20、および x=33 の位置にラインを表示します。

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

ラインのスタイルと色。文字と記号を含む文字ベクトルまたは string スカラーとして指定します。文字と記号の順番は任意です。ライン スタイル、ラインの色、またはその両方を指定できます。'o' などのマーカー記号は無視されます。

例: '--g' は緑色の破線です。

ライン スタイル説明結果として得られる線
"-"実線

Sample of solid line

"--"破線

Sample of dashed line

":"点線

Sample of dotted line

"-."一点鎖線

Sample of dash-dotted line, with alternating dashes and dots

色名省略名外観
'red''r'

Sample of the color red

'green''g'

Sample of the color green

'blue''b'

Sample of the color blue

'cyan' 'c'

Sample of the color cyan

'magenta''m'

Sample of the color magenta

'yellow''y'

Sample of the color yellow

'black''k'

Sample of the color black

'white''w'

Sample of the color white

ターゲット座標軸。Axes オブジェクトとして指定します。xline によって現在の座標軸以外の座標軸にプロットする場合は、この引数を使用します。

ライン ラベル。文字ベクトル、string スカラー、文字ベクトルの cell 配列、または string 配列として指定します。

1 本のラインのラベルを作成

1 行のテキストを表示するには、文字ベクトルまたは string スカラーを指定します。複数行のテキストを表示するには、文字ベクトルの cell 配列または string 配列を指定します。

表示labels の指定方法
1 行のテキスト文字ベクトルまたは string スカラーを指定します。

xline(12,'-','Sample')

A vertical line in an axes with a label

複数行のテキスト文字ベクトルの cell 配列または string 配列を指定します。配列の各要素は、テキストの各行です。
xline(12,'-',{'Sample','x=12'})

A vertical line in an axes with a label that has two lines of text

複数のラインのラベルを作成

すべてのラインの横に同じテキストを表示するには、文字ベクトルまたは string スカラーを指定します。ラインごとに異なるテキストを表示するには、文字ベクトルの cell 配列または string 配列を指定します。

表示labels の指定方法
1 つの共有のテキスト ラベル文字ベクトルまたは string スカラーを指定します。

xline([13 20 33],'-','Sample')

Three vertical lines in an axes with matching labels

ラインごとに異なるラベル文字ベクトルの cell 配列または string 配列を指定します。配列の各要素は、それぞれのラインのラベルです。labels 配列の要素の数は x の長さと一致しなければなりません。
label = {'Sample 1','Sample 2','Sample 3'};
xline([13 20 33],'-',label)

Three vertical lines in an axes with different labels

一部が複数行の異なるラベル文字ベクトルの cell 配列または string 配列を作成します。関数 sprintf を使用してテキストに改行文字 ('\n') を挿入します。
label = {'Sample 1',sprintf('Sample 2\nx=20'),'Sample 3'};
xline([13 20 33],'-',label)

Three vertical lines in an axes with different labels. The label for the second line has two lines of text.

名前と値の引数

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

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

例: xline(5,'LabelVerticalAlignment','middle') は、ラベルの垂直方向の配置を 'middle' として指定します。

メモ

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

ラインの色。RGB 3 成分、16 進数カラー コード、色名、または省略名として指定します。

カスタム色を使用する場合は、RGB 3 成分または 16 進数カラー コードを指定します。

  • RGB 3 成分は、色の赤、緑、青成分の強度を指定する 3 成分の行ベクトルです。強度値は [0,1] の範囲でなければなりません。たとえば [0.4 0.6 0.7] のようになります。

  • 16 進数カラー コードは、ハッシュ記号 (#) で始まり、3 桁または 6 桁の 0 から F までの範囲の 16 進数が続く string スカラーまたは文字ベクトルです。この値は大文字と小文字を区別しません。したがって、カラー コード "#FF8800""#ff8800""#F80"、および "#f80" は等価です。

あるいは、名前を使用して一部の一般的な色を指定できます。次の表に、名前の付いた色オプション、等価の RGB 3 成分、および 16 進数カラー コードを示します。

色名省略名RGB 3 成分16 進数カラー コード外観
"red""r"[1 0 0]"#FF0000"

Sample of the color red

"green""g"[0 1 0]"#00FF00"

Sample of the color green

"blue""b"[0 0 1]"#0000FF"

Sample of the color blue

"cyan" "c"[0 1 1]"#00FFFF"

Sample of the color cyan

"magenta""m"[1 0 1]"#FF00FF"

Sample of the color magenta

"yellow""y"[1 1 0]"#FFFF00"

Sample of the color yellow

"black""k"[0 0 0]"#000000"

Sample of the color black

"white""w"[1 1 1]"#FFFFFF"

Sample of the color white

"none"該当なし該当なし該当なし色なし

MATLAB® の多くのタイプのプロットで使用されている既定の色の RGB 3 成分および 16 進数カラー コードを次に示します。

RGB 3 成分16 進数カラー コード外観
[0 0.4470 0.7410]"#0072BD"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

例: 'g'

例: [0.6 0.2 0.5]

例: '#D2F9A7'

ライン幅。ポイント単位の正の値として指定します。

凡例ラベル。文字ベクトルまたは string スカラーとして指定します。legend コマンドを呼び出すまで、凡例は表示されません。テキストを指定しない場合、legend'dataN' 形式を使用してラベルを設定します。

ラインに対するラベルの水平方向の配置。次の表のいずれかのオプションとして指定します。

オプション説明
'right'ラインの右側。

Vertical line with the label to the right of the line

'left'ラインの左側。

Vertical line with the label to the left of the line

'center'ラインの中心。ラベルによってラインは分割されます。

Vertical line with the label centered with the line

ラインに対するラベルの垂直方向の配置。次の表のいずれかのオプションとして指定します。

オプション説明
'top'ラインの上方

Vertical line with the label at the top of the line

'middle'ラインの中央

Vertical line with the label vertically centered

'bottom'ラインの下方

Vertical line with the label at the bottom of the line

ラベルの向き。'aligned' または 'horizontal' として指定します。例を表に示します。

向き説明
'aligned'ラベルの向きはラインの向きと同じです。

Vertical line with a vertical label

'horizontal'ラインの向きに関係なく、ラベルは水平です。

Vertical line with a horizontal label

アルゴリズム

座標軸の 3 次元表示で、定数直線は z 軸の範囲の中点に位置する x-y 平面に表示されます。座標軸が回転すると、それに従って定数直線も回転します。

バージョン履歴

R2018b で導入