Main Content

colororder

複数データ系列を可視化するための色の順序を設定

R2019b 以降

説明

colororder(newcolors) は、現在の Figure での色の順序を設定します。Figure が存在しない場合は MATLAB® が Figure を作成し、その Figure について色の順序を設定します。Figure の色の順序を設定するときは、その Figure 内にあるすべての座標軸に対し色の順序を設定します。

colororder(target,newcolors) は、現在の Figure ではなく、ターゲットの座標軸、Figure、またはチャートについて色の順序を設定します。

C = colororder は、現在の Figure について色の順序の行列を返します。

C = colororder(target) は、ターゲットの Figure、座標軸、またはチャートについて色の順序の行列を返します。

すべて折りたたむ

Figure の色の順序を 4 色に設定します。1 つの x 座標ベクトルと 4 つの y 座標ベクトルを定義します。次に、それぞれの座標セットをプロットします。

newcolors = [0.83 0.14 0.14
             1.00 0.54 0.00
             0.47 0.25 0.80
             0.25 0.80 0.54];
         
colororder(newcolors)

% Define coordinates
x = linspace(0,10);
y1 = sin(x);
y2 = sin(x-0.5);
y3 = sin(x-1);
y4 = sin(x-1.5);

% Plot coordinates
plot(x,y1,'LineWidth',2)
hold on
plot(x,y2,'LineWidth',2)
plot(x,y3,'LineWidth',2)
plot(x,y4,'LineWidth',2)
hold off

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

同心の四分円を 7 つプロットします。

hold on
for r=1:7
    x = linspace(0,r,500);
    y = sqrt(r.^2-x.^2);
    plot(x,y,'LineWidth',15)
end

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

色の順序を、7 つの 16 進数カラー コードに変更します。

newcolors = {'#F00','#F80','#FF0','#0B0','#00F','#50F','#A0F'};
colororder(newcolors)

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

3 系列のバーを表示します。色の順序を、青、紫、グレーに設定します。

bar([10 20 30; 25 35 45; 30 40 52])
newcolors = [0 0.5 1; 0.5 0 1; 0.7 0.7 0.7];
colororder(newcolors)

Figure contains an axes object. The axes object contains 3 objects of type bar.

yyaxis を呼び出す前に Figure の色の順序を設定すると、各 y 軸の色が設定されます。左側では最初の色を使用し、右側では 2 番目の色を使用します。2 つより多くの色を指定した場合、追加の色はどちら側でも使用されません。

newcolors を、2 つの RGB 3 成分を含む行列として定義します。Figure の色の順序を設定し、左側に対して 2 本のラインをプロットします。次に、右側に対して 2 本のラインをプロットします。

newcolors = [0.40 0.30 0.90; 0.50 0.65 0.15];
colororder(newcolors)

% Left side
yyaxis left
plot([1 2; 3 4])

% Right side
yyaxis right
plot([4 3; 2 1])

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

yyaxis を呼び出した後に Figure の色の順序を設定すると、アクティブな側の色が設定されます。

左側の y 軸をアクティブにして 3 本のラインをプロットします。ライン スタイルの順序を 1 本の実線に設定し、y 軸の色を青に変更します。次に、色の順序を 3 階調の青に設定します。

% Left side
yyaxis left
plot([1 2 3; 4 5 6])
ax = gca;
ax.LineStyleOrder = '-';
ax.YColor = 'blue';
leftcolors = [0 0 1; 0 0.50 1; 0 0.80 1];
colororder(leftcolors)

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

右側の y 軸をアクティブにして 2 本のラインをプロットします。y 軸の色を黒に変更します。次に、色の順序を黒に設定します。

% Right side
yyaxis right
plot([4 3; 2 1])
ax.YColor = 'black';
colororder('black')

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

色の引数を指定してプロット関数を呼び出すと、プロット関数はその色を使用し、色の順序における次の色は使用しません。

Figure の色の順序を、赤、マゼンタ、青に設定します。関数 scatter を呼び出して散布点の系列をプロットします。次に、2 番目の点の系列をプロットし、マーカーを黒のアスタリスクとして指定します。

newcolors = {'red','magenta','blue'};
colororder(newcolors)
scatter(1:10,rand(1,10),'filled')
hold on
scatter(1:10,rand(1,10),'*k')

Figure contains an axes object. The axes object contains 2 objects of type scatter.

マーカーの色を指定せずに、3 番目の点の系列をプロットします。この系列では、色の順序の 3 番目の色である青が使用されることに注目してください。

scatter(1:10,rand(1,10),'filled')
hold off

Figure contains an axes object. The axes object contains 3 objects of type scatter.

タイル表示チャート レイアウトを作成し、最初のタイルに 3 本のラインをプロットします。

tiledlayout('flow')
nexttile
plot([1 2 3; 4 5 6],'LineWidth',2)

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

2 番目のタイルの axes オブジェクトを取得する戻り引数を指定して関数 nexttile を呼び出します。2 番目のタイルに 3 本のラインをプロットします。次に、座標軸に対する色の順序の行列を取得して、C に出力を返します。C の最初の色を紫に変更し、座標軸の色の順序を変更後の C 行列に設定します。

ax = nexttile;
plot(ax,[4 5 6; 1 2 3],'LineWidth',2)
C = colororder(ax);
C(1,:) = [0.5 0 1];
colororder(ax,C)

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

入力引数

すべて折りたたむ

新しい色。RGB 3 成分の行列、色名の配列、または 'default' として指定します。

RGB 3 成分の行列

各行が RGB 3 成分である m 行 3 列の行列を指定します。RGB 3 成分は、色の赤、緑、青成分の強度を含む 3 要素ベクトルです。強度値は [0,1] の範囲でなければなりません。たとえば、次の行列は新しい色を、青、濃い緑、オレンジとして定義します。

newcolors = [1.0 0.0 0.0
             0.0 0.4 0.0
             1.0 0.5 0.0];

色名または 16 進数カラー コードの配列

色名、省略名、16 進数カラー コードを任意に組み合わせて指定します。

  • 1 つの色を指定するには、newcolors を文字ベクトルまたは string スカラーに設定。たとえば、newcolors = 'red' は、色の順序の唯一の色として赤を指定します。

  • 複数の色を指定するには、newcolors を文字ベクトルの cell 配列または string 配列に設定。たとえば、newcolors = {'red','green','blue'} は、色として赤、緑、青を指定します。

16 進数カラー コードはハッシュ記号 (#) で開始し、0F の範囲で 3 桁または 6 桁の 16 進数が続きます。これらの値では大文字小文字は区別されません。したがって、カラー コード '#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

既定の色

'default' を指定すると、色の順序が既定の 7 色に設定されます。このオプションは、色の順序を一時的に変更した後にリセットする場合に便利です。既定の色の 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

データ型: single | double | char | cell | string

ターゲット。次の値のいずれかとして指定します。

  • Figure。新しい色は、Figure 内のすべての座標軸の内容に影響します。

  • Axes オブジェクト、PolarAxes オブジェクト、または GeographicAxes オブジェクトなど、任意のタイプの axes オブジェクト。新しい色は、指定した座標軸の内容にのみ影響します。

  • 関数 stackedplotscatterhistogramparallelplotgeobubble で作成されたスタンドアロンの可視化。

詳細

すべて折りたたむ

色の順序

色の順序は、1 つの座標軸内で複数のデータ系列をプロットするために MATLAB が使用する一連の色を制御します。LineScatterBar などのグラフィックス オブジェクトには、作成順序に従って色が割り当てられます。

色は、行列として座標軸の ColorOrder プロパティに保存されます。関数 colororder を呼び出すと、行列が置き換えられます。

ヒント

  • Figure に対し色の順序を設定すると、その色はプロット関数を呼び出すときにも存続します。ただし、axes オブジェクトを関数 colororder に渡す場合は、プロット関数を呼び出すときに色を存続させるために、まず hold on を呼び出さなければなりません。

  • 座標軸で ColorOrderIndex プロパティまたは LineStyleOrderIndex プロパティを設定する場合、新しい色の順序は既存のプロットには影響しません。新しい色は、hold on を呼び出し、プロット関数を呼び出した後に初めて有効になります。

バージョン履歴

R2019b で導入

参考

関数

プロパティ