Main Content

colormap

現在のカラーマップの表示と設定

説明

カラーマップの設定

colormap map は、現在の Figure のカラーマップを指定した事前定義のカラーマップに設定します。たとえば、colormap hot は、カラーマップを hot に設定します。

Figure のカラーマップを設定した場合、Figure の座標軸とチャートは同じカラーマップを使用します。新しいカラーマップの長さ (色の数) は現在のカラーマップと同じになります。この構文を使用する場合、カラーマップにカスタムの長さは指定できません。カラーマップの詳細については、詳細の節を参照してください。

colormap(map) は、現在の Figure のカラーマップを map で指定されたカラーマップに設定します。

colormap(target,map) は、現在の Figure の代わりに、target で指定された Figure、座標軸、またはスタンドアロンの可視化にカラーマップを設定します。

cmap = colormap(___) はカラーマップを設定し、RGB 3 成分からなる 3 列の行列として返します。前述の小かっこを使用する構文のいずれかで出力引数として cmap を指定します。

現在のカラーマップの取得

cmap = colormap は、現在の Figure のカラーマップを RGB 3 成分から成る 3 列の行列として返します。

cmap = colormap(target) は、target で指定した Figure、座標軸またはスタンドアロンの可視化のカラーマップを返します。

すべて折りたたむ

表面プロットを作成し、カラーマップを winter に設定します。

surf(peaks)
colormap winter

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

まず、現在の Figure のカラーマップを summer に変更します。

surf(peaks)
colormap summer

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

次に、カラーマップをシステムの既定値に戻します。別の既定値を指定していない限り、既定のカラーマップは parula です。

colormap default

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

R2019b 以降、関数 tiledlayout および nexttile を使用して、プロットをタイル表示できます。関数 tiledlayout を呼び出して、2 行 1 列のタイル表示チャート レイアウトを作成します。関数 nexttile を呼び出して、axes オブジェクト ax1 および ax2 を作成します。関数 colormap に axes オブジェクトを渡して、座標軸ごとに異なるマップを指定します。上の座標軸では、spring カラーマップを使用して表面プロットを作成します。下の座標軸では、winter カラーマップを使用して表面プロットを作成します。

tiledlayout(2,1)
ax1 = nexttile;
surf(peaks)
colormap(ax1,spring)

ax2 = nexttile; 
surf(peaks)
colormap(ax2,winter)

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

組み込みのカラーマップに入力引数として整数を渡し、カラーマップの使用する色の数を指定します。parula カラーマップの色を 5 つ使用します。

mesh(peaks)
colormap(parula(5))

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

0.0 ~ 1.0 の範囲の値から成る 3 列の行列を定義して、カスタムのカラーマップを作成します。各行で RGB 3 成分を定義します。1 列目に赤の強度を指定します。2 列目に緑の強度を指定します。3 列目に青の強度を指定します。

最初の 2 列をゼロに設定して、青の値のカラーマップを使用します。

map = [0 0 0.3
    0 0 0.4
    0 0 0.5
    0 0 0.6
    0 0 0.8
    0 0 1.0];

surf(peaks)
colormap(map)

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

関数 peaks の表面プロットを作成し、カラーマップを指定します。

mesh(peaks)
colormap(autumn(5))

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

プロットで使用されている色を定義する値の 3 列の行列を返します。各行に、カラーマップの 1 つの色を示す RGB 3 成分の値が 1 つずつ格納されます。

cmap = colormap
cmap = 5×3

    1.0000         0         0
    1.0000    0.2500         0
    1.0000    0.5000         0
    1.0000    0.7500         0
    1.0000    1.0000         0

関数 colormap に axes オブジェクトを渡して、特定の座標軸のカラーマップの値を返します。

R2019b 以降の新しい関数である関数 tiledlayout および nexttile を使用して、2 つのプロットのタイル配置を作成します。関数 tiledlayout を呼び出して、2 行 1 列のタイル表示チャート レイアウトを作成します。関数 nexttile を呼び出して、axes オブジェクト ax1 および ax2 を作成します。次に、別々のカラーマップをもつ 2 つの塗りつぶし等高線図を表示します。

tiledlayout(2,1)
ax1 = nexttile;
contourf(peaks)
colormap(ax1,hot(8))

ax2 = nexttile;
contourf(peaks)
colormap(ax2,pink)

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

関数 colormapax1 を渡して、上のプロットで使用したカラーマップの値を返します。各行に、カラーマップの 1 つの色を示す RGB 3 成分の値が 1 つずつ格納されます。

cmap = colormap(ax1)
cmap = 8×3

    0.3333         0         0
    0.6667         0         0
    1.0000         0         0
    1.0000    0.3333         0
    1.0000    0.6667         0
    1.0000    1.0000         0
    1.0000    1.0000    0.5000
    1.0000    1.0000    1.0000

イメージ X とそれに関連付けられたカラーマップ map を返す spine データ セットを読み込みます。関数 image を使用して X を表示し、カラーマップを map に設定します。

load spine
image(X)
colormap(map)

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

入力引数

すべて折りたたむ

新しいカラー スキームのカラーマップ。カラーマップの名前、RGB 3 成分から成る 3 列の行列、または 'default' として指定します。カラーマップの名前は、現在のカラーマップと同じ数の色をもつ事前定義されたカラーマップを指定します。RGB 3 成分から成る 3 列の行列は、カスタムのカラーマップを指定します。独自の行列を作成できます。あるいは、事前定義されたカラーマップ関数のいずれかを呼び出して行列を作成することもできます。たとえば、colormap(parula(10)) は、現在の Figure のカラーマップを parula カラーマップから選択した 10 色に設定します。

'default' の値は、ターゲット オブジェクトのカラーマップを既定のカラーマップに設定します。

カラーマップの名前

次の表に事前定義されたカラーマップを示します。

カラーマップの名前カラー スケール

parula

Colorbar showing the colors of the parula colormap. The colormap starts at dark blue and transitions to lighter blue, green, orange and yellow. The transitions between colors are more perceptually uniform than in most other colormaps.

turbo

Colorbar showing the colors of the turbo colormap. The colormap starts at dark blue and transitions to lighter blue, bright green, orange, yellow, and dark red. This colormap is similar to jet, but the transitions between colors are more perceptually uniform than in jet.

hsv

Colorbar showing the colors of the hsv colormap. The colormap starts at red and transitions to yellow, bright green, cyan, dark blue, magenta, and bright orange.

hot

Colorbar showing the colors of the hot colormap. The colormap starts at dark red and transitions to bright red, orange, yellow, and white.

cool

Colorbar showing the colors of the cool colormap. The colormap starts at cyan and transitions to light blue, light purple, and magenta.

spring

Colorbar showing the colors of the spring colormap. The colormap starts at magenta and transitions to pink, light orange, and yellow.

summer

Colorbar showing the colors of the summer colormap. The colormap starts at medium green and transitions to yellow.

autumn

Colorbar showing the colors of the autumn colormap. The colormap starts at bright orange and transitions to yellow.

winter

Colorbar showing the colors of the winter colormap. The colormap starts at dark blue and transitions to bright green.

gray

Colorbar showing the gray colormap. The colormap starts at black and transitions to white.

bone

Colorbar showing the bone colormap. This colormap has colors that are approximately gray with a slight blue color tint. The colormap starts at dark gray and transitions to white.

copper

Colorbar showing the copper colormap. This colormap starts at black and transitions to a medium orange, similar to the color of copper.

pink

Colorbar showing the pink colormap. This colormap starts at dark red and transitions to dark pink, tan, and white.

sky (R2023a 以降)

Colorbar showing the sky colormap. This colormap starts at a very light shade of blue and transitions to a darker shade of blue.

abyss (R2023b 以降)

Colorbar showing the abyss colormap. This colormap starts at a very dark shade of blue and transitions to a lighter shade of blue.

jet

Colorbar showing the colors of the jet colormap. The colormap starts at dark blue and transitions to light blue, bright green, orange, yellow, and dark red.

lines

Colorbar showing the colors of the lines colormap. The colormap contains a repeating pattern of colors: dark blue, dark orange, dark yellow, dark purple, medium green, light blue, and dark red.

colorcube

Colorbar showing the colors of the colorcube colormap. The colormap is a course sampling of the RGB colorspace.

prism

Colorbar showing the colors of the prism colormap. The colormap contains a repeating pattern of colors: red, orange, yellow, green, blue, and purple.

flag

Colorbar showing the colors of the flag colormap. The colormap contains a repeating pattern of colors: red, white, blue, and black.

white

Colorbar showing the white colormap, which is entirely white.

3 列の行列

カスタムのカラーマップを作成するには、map に RGB 3 成分から成る 3 列の行列を指定し、各行で 1 つの色を定義します。RGB 3 成分は、色の赤、緑、青成分の強度を指定する 3 成分の行ベクトルです。強度値は範囲 [0, 1] の double 値または single 値か、範囲 [0, 255] の uint8 の値にすることができます。たとえば次の行列では 5 色のカラーマップを定義しています。

map = [0.2 0.1 0.5
    0.1 0.5 0.8
    0.2 0.7 0.6
    0.8 0.7 0.3
    0.9 1 0];

次の表に一般的な色に対応する RGB 3 成分の値を示します。

double または single の RGB 3 成分uint8 の RGB 3 成分
[1 1 0][255 255 0]
マゼンタ[1 0 1][255 0 255]
シアン[0 1 1][0 255 255]
[1 0 0][255 0 0]
[0 1 0][0 255 0]
[0 0 1][0 0 255]
[1 1 1][255 255 255]
[0 0 0][0 0 0]

データ型: char | double | single | uint8

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

  • Figure オブジェクト。Figure のカラーマップは、Figure 内のすべての座標軸のプロットに適用されます。

  • Axes オブジェクト、PolarAxes オブジェクト、または GeographicAxes オブジェクト。Figure 内の異なる座標軸に対して、固有のカラーマップを定義できます。

  • Colormap プロパティをもつスタンドアロンの可視化。たとえば、HeatmapChart オブジェクトのカラーマップの変更またはクエリができます。

出力引数

すべて折りたたむ

カラーマップの値。RGB 3 成分から成る 3 列の行列として返されます。行列の各行に、カラーマップの 1 つの色を定義する RGB 3 成分が 1 つずつ格納されます。値の範囲は [0, 1] です。

詳細

すべて折りたたむ

カラーマップ

"カラーマップ" とは、surface、image および patch の各オブジェクトのようなグラフィックス オブジェクトの色を定義する値の行列です。MATLAB® は、データ値をカラーマップ内の色にマップして、オブジェクトを描画します。

カラーマップの長さは任意ですが、幅は 3 列でなければなりません。行列の各行は、RGB 3 成分を使用して 1 色を定義します。RGB 3 成分は、色の赤、緑、青成分の強度を指定する 3 成分の行ベクトルです。通常、強度値は範囲 [0, 1] の double 値または single 値です。0 の値は色なし、1 の値は最大強度を表します。たとえば、このコマンドは、黒、赤、緑、青、白の 5 色をもつカラーマップを作成します。

mymap = [0 0 0
    1 0 0
    0 1 0
    0 0 1
    1 1 1];

可視化のカラー スキームを変更するには、関数 colormap を呼び出して、座標軸または Figure を含むカラーマップを変更します。たとえば、次のコマンドは表面プロットを作成し、Figure のカラーマップを mymap に設定します。

surf(peaks)
colormap(mymap)

Surface plotted with a custom colormap containing five colors: black, red, green, blue, and black.

ヒント

  • カラーマップの範囲、およびこれらの範囲とデータの範囲との関連付けを制御するには、関数 clim を使用します。

    R2022a より前: caxis を使用します。その構文と引数は clim と同じです。

バージョン履歴

R2006a より前に導入

すべて展開する