MatrixPlot[m]
行列中の要素の値を視覚的に表すプロットを生成する.
MatrixPlot
MatrixPlot[m]
行列中の要素の値を視覚的に表すプロットを生成する.
詳細とオプション
- MatrixPlot[m]は,行列が一般的にフォーマットされるのと同じように,デフォルトで m の連続する行をページの下に向けて,連続する列を横に向けて並べる.
- MatrixPlotは,デフォルトで,ゼロ値を白で,負の値を青みがかった色で,正の値を赤みがかった色で表示する.
- MatrixPlotでは,ArrayPlotのオプションに以下の変更を加えたものが使える. [全オプションのリスト]
-
ClippingStyle Automatic 切り取られた値をどのように表示するか Frame True プロットの周囲に枠を描くかどうか FrameTicks All 枠にどのような目盛を入れるか MaxPlotPoints Automatic 含める点の最大数 - PlotRange->r は,-r から+r までの間の aijのみを示すように指定する.
- デフォルト設定のColorFunctionScaling->Trueでは,各行列要素の相対的な値とランキングに基づいてスケーリングが行われる.最終的にスケールされた値は常に0から1の間にあり,スケールされた値0.5が行列要素の値0に相当する.
- デフォルト設定のMaxPlotPoints->Automaticでは,非常に大きいあるいは疎な行列は,MatrixPlotが生成するプロットで構造が見えるようにダウンサンプルされる.
- MatrixPlotはSparseArrayオブジェクトに使うことができる.
全オプションのリスト
例題
すべて開く すべて閉じる例 (4)
MatrixPlot[{{1, 2, 1}, {3, 0, 1}, {0, 0, -1}}]MatrixPlot[{{1, 2, 1}, {3, 0, 1}, {0, 0, -1}}, ColorFunction -> "Monochrome"]MatrixPlot[Fourier[Table[UnitStep[i, 4 - i] UnitStep[j, 7 - j], {i, -50, 50}, {j, -50, 50}]]]m = ExampleData[{"Matrix", "HB/west0381"}, "Matrix"]MatrixPlot[m]スコープ (19)
データ (10)
m = Inverse@Table[Which[i == j, 2., i == j + 1 || i == j - 1, -1., True, 0.], {i, 100}, {j, 100}];MatrixPlot[m]m = Import["LinearAlgebraExamples/Data/dwg961b.cua"]MatrixPlot[m]長方形ではない「行列」を,欠けている要素を透過的にしてプロットする:
MatrixPlot[Table[Binomial[n, k], {n, 0, 25}, {k, 0, n}], Background -> StandardGray]MatrixPlot[{{4, 2, 1}, {3, 0, -2}, {0, 0, -1}}]零近くの項目は少し灰色がかった表示にする.零に非常に近い項目は白くなることがある:
MatrixPlot[{{1, 2, 3}, {1.*^-16, 0.00001, -0.00001}, {-2, -1, -3}}]MatrixPlot[{{1, 2, 3}, {-1 + 2I, -2 + 3I, -3 - 10I}, {1 + 2I, 2 + 3I, 3 - 10I}}]Noneは欠測値と解釈され,透過性を使って表示される:
MatrixPlot[{{3, 1, 2}, {-1, None, -2}, {-1, -2, -3}}, Background -> StandardGray]None以外の記号値は暗赤色で示される:
MatrixPlot[{{1, 2, 3}, {a, 0.00001, -0.00001}, {-2, -1, -3}}]非常に疎な行列の場合,項目がよく見えるように色は暗目に表示される:
Row[{MatrixPlot[Table[1, {i, 20}, {j, 20}]], MatrixPlot[SparseArray[{{10, 10} -> 1}, {20, 20}]]}]MatrixPlot[{{-1.`100, 2, Pi}, {Sqrt[2], 1 / 2, Catalan}}]プレゼンテーション (9)
m = Block[{n = 100}, Table[Exp[i j 2Pi I / n], {i, 0, n - 1}, {j, 0, n - 1}]];MatrixPlot[m, FrameLabel -> {i, j}, PlotLabel -> "Fourier Matrix"]MatrixPlot[{{Red, Green, 1, 2}, {Blue, Yellow, -1, -2}}]MatrixPlot[Table[Cos[x y / 150.], {x, -50, 50}, {y, -50, 50}], ColorFunction -> "Rainbow"]m = ExampleData[{"Matrix", "WEST2021"}, "Matrix"]MatrixPlot[m, ColorFunction -> "Monochrome"]MatrixPlot[Table[Cos[x y / 150.], {x, -50, 50}, {y, -50, 50}], ColorFunctionScaling -> False, ColorFunction -> (Blend[{{-1, Blue}, {0, White}, {1, Red}}, #]&)]ColorRulesを使って異なる値を色分けする:
MatrixPlot[Table[Mod[i ^ 2 + j ^ 2, 3], {i, 20}, {j, 20}], ColorRules -> {0 -> Red, 1 -> Green, 2 -> Blue}]優先順位はColorRulesを高くし,ColorRulesとColorFunctionの両方を使って要素に色付けする:
MatrixPlot[Table[Mod[i ^ 2 + j ^ 2, 5], {i, 20}, {j, 20}], ColorRules -> {0 -> Red, 1 -> Green, 2 -> Blue}]MeshとMeshStyleを使ってオーバーレイメッシュを提供する:
MatrixPlot[SparseArray[{Band[{3, 1}] -> -1, Band[{1, 1}] -> 1, Band[{1, 5}] -> 4}, {10, 10}], Mesh -> All, MeshStyle -> Directive[Gray, Dashed]]MatrixPlot[Table[Mod[i ^ 2 + j ^ 2, 5], {i, 20}, {j, 20}], PlotTheme -> "Marketing"]オプション (33)
AspectRatio (2)
Background (2)
Backgroundは通常辺の周囲のみで可視となる:
MatrixPlot[{{1, 0, 0, 0.3}, {1, 1, 0, 0.3}, {1, 0, 1, 0.7}}, Background -> StandardGray]明示的な項目がNoneのときは常に背景が「透けて見える」:
MatrixPlot[{{1, 0, 0, None}, {1, 1, 0, None}, {1, None, 1, 0.7}}, Background -> Blue]ClippingStyle (3)
デフォルトで,切り取られた値は鮮やかな赤または青に色付けられる:
MatrixPlot[{{1, 10, 1}, {100, 0, 1}, {-10, 0, -1}}, PlotRange -> {-1, 1}, ClippingStyle -> Automatic]MatrixPlot[{{1, 10, 1}, {100, 0, 1}, {-10, 0, -1}}, PlotRange -> {-1, 1}, ClippingStyle -> {Green, Yellow}]Noneを使ってスタイルを使わないようにし,そのセルの背景を見せる:
MatrixPlot[{{1, 10, 1}, {100, 0, 1}, {-10, 0, -1}}, PlotRange -> {-1, 1}, ClippingStyle -> None, Background -> StandardGray]ColorFunction (5)
MatrixPlot[Table[x ^ 2 - y ^ 2, {x, -10, 10}, {y, -10, 10}],
ColorFunction -> Hue]MatrixPlot[Table[x ^ 2 - y ^ 2, {x, -10, 10}, {y, -10, 10}], ColorFunction -> (RGBColor[1 - #, #, 1 / 2]&)]ColorDataから名前付きの色勾配を使う:
MatrixPlot[Table[x ^ 2 - y ^ 2, {x, -10, 10}, {y, -10, 10}], ColorFunction -> "TemperatureMap"]ある値について色関数が定義されていない場合,暗赤色が代りに使われる:
MatrixPlot[{{1, 2}, {a, 4}}, ColorFunction -> Hue]MatrixPlot[{{1, 2}, {a, 4}}, ColorFunction -> (If[# === a, Yellow, Hue[#]]&)]MatrixPlot[{{1 + I, 2 + I}, {3 + I, 4}}, ColorFunction -> Hue]MatrixPlot[{{1, 2}, {3, 4}}, ColorFunction -> Hue]ColorFunctionScaling (4)
デフォルトで,広い範囲の値の弁別には項目の非線形スケーリングが使われる:
MatrixPlot[Table[x ^ 4 - y ^ 4, {x, -10, 10}, {y, -10, 10}], ColorFunction -> "TemperatureMap"]ColorFunctionScaling->Falseとすると項目はスケールされない:
MatrixPlot[Table[x ^ 4 - y ^ 4, {x, -10, 10}, {y, -10, 10}], ColorFunction -> (ColorData["TemperatureMap"][Rescale[#, {-10 ^ 4, 10 ^ 4}]]&), ColorFunctionScaling -> False]ColorFunctionScaling->Falseとすると,MatrixPlotはArrayPlotのように振る舞う:
MatrixPlot[{{0, 1, 2}}, ColorFunctionScaling -> False]ArrayPlot[{{0, 1, 2}}]ColorFunctionScalingはColorRulesには効果がない:
Table[MatrixPlot[{{0, 1}}, ColorRules -> {0 -> Red, 1 -> Green}, ColorFunctionScaling -> cf], {cf, {True, False}}]ColorRules (6)
MatrixPlot[Table[Mod[i ^ 2 + j ^ 2, 5], {i, 30}, {j, 30}], ColorRules -> {0 -> White, 1 -> Red, 2 -> Blue, 3 -> Yellow, 4 -> Green}]MatrixPlot[Table[Mod[i ^ 2 + j ^ 2, 5], {i, 30}, {j, 30}], ColorRules -> {1 -> Red, 2 -> Blue, 3 -> Yellow, _ -> Gray}]MatrixPlot[Transpose[Permutations[{a, b, c}]], ColorRules -> {a -> Red, b -> Yellow, c -> Blue}, Mesh -> True]ColorRulesで任意のパターンを使う:
MatrixPlot[{{-1, 0, 1}, {2, 3, -5}, {1, 2, 1}}, ColorRules -> {_ ? EvenQ -> Red, 1 | -1 -> Blue, x_ /; x < -1 -> Black}]MatrixPlot[{{1, 0, 1}, {1, 1, 0}}, ColorRules -> {1 -> Red, 0 -> Blue, 1 -> Black}]ColorRulesをColorFunctionとともに使うことができる.優先順位はColorRulesの方が高い:
MatrixPlot[Table[Mod[i ^ 2 + j ^ 2, 5], {i, 30}, {j, 30}], ColorRules -> {1 -> Red, 2 -> Blue, 3 -> Yellow}, ColorFunction -> (Gray&)]DataReversed (1)
MaxPlotPoints (1)
デフォルトで,サンプルの大きいおよび/または疎な行列をダウンサンプルするのに自動メソッドが使われる:
sp = SparseArray[Table[{RandomInteger[{1, 1000}], RandomInteger[{1, 1000}]} -> 1, {3000}], {1000, 1000}]MatrixPlot[sp]MatrixPlot[sp, MaxPlotPoints -> Infinity]MaxPlotPointsのダウンサンプルした値を明示的に設定する:
Table[MatrixPlot[sp, MaxPlotPoints -> pp], {pp, {50, 100, 200}}]結果のプロットの視覚的外観もまたColorFunctionの選択の影響を受ける:
MatrixPlot[sp, ColorFunction -> "Monochrome", MaxPlotPoints -> Infinity]Mesh (3)
MatrixPlot[SparseArray[{Band[{3, 1}] -> -1, Band[{1, 1}] -> 1, Band[{1, 5}] -> 4}, {10, 10}], Mesh -> All]MatrixPlot[SparseArray[{Band[{3, 1}] -> -1, Band[{1, 1}] -> 1, Band[{1, 5}] -> 4}, {10, 10}], Mesh -> {19, 1}]MatrixPlot[SparseArray[{Band[{3, 1}] -> -1, Band[{1, 1}] -> 1, Band[{1, 5}] -> 4}, {10, 10}], Mesh -> {None, Table[{i, Hue[i / 10]}, {i, 0, 10}]}]MeshStyle (1)
PlotRange (3)
MatrixPlot[Table[1 / (2 + Sin[x ^ 2 + y ^ 2]) - 0.75, {x, -3, 3, .05}, {y, -3, 3, .05}]]MatrixPlot[Table[1 / (2 + Sin[x ^ 2 + y ^ 2]) - 0.75, {x, -3, 3, .05}, {y, -3, 3, .05}], PlotRange -> 1]PlotRangeの最初の2項目は含める行と列の範囲を指定する:
MatrixPlot[Table[1 / (2 + Sin[x ^ 2 + y ^ 2]) - 0.75, {x, -3, 3, .05}, {y, -3, 3, .05}], PlotRange -> {{20, 60}, All, All}]アプリケーション (3)
sp = Import["LinearAlgebraExamples/Data/wm1.rra"]MatrixPlot[sp]MatrixPlot[sp, PlotRange -> {{1, 60}, {1, 60}}, ClippingStyle -> {Red, Red}]MatrixPlot[Im[Table[Exp[2. Pi I i j / 32], {i, 0, 32}, {j, 0, 32}]]]MatrixPlot[Table[Evaluate[Sum[Sin[RandomReal[10, 2].{x, y}], {5}]], {x, 0, 5, .1}, {y, 0, 5, .1}]]特性と関係 (6)
MatrixPlotでは負の項目は寒色,正の項目は暖色になる:
MatrixPlot[{{1, 2, 3}, {-1, 0, -3}, {4, 0, -1}}]ArrayPlotはグレースケールを使う:
ArrayPlot[{{1, 2, 3}, {-1, 0, -3}, {4, 0, -1}}]MatrixPlotは広範囲の値を弁別するために行列の項目を再スケールする:
MatrixPlot[{{100, 2, 3}, {-1, 0, -3}, {4, 0, -50}}]MatrixPlot[{{50, 2, 3}, {-1, 0, -3}, {4, 0, -50}}, ColorFunctionScaling -> False]ReliefPlotを医療データや地理データに使う:
ReliefPlot[Import["http://exampledata.wolfram.com/hailey.dem.gz", "Data"], ColorFunction -> "GreenBrownTerrain", MaxPlotPoints -> 200]連続密度からサンプルされた構造化データと非構造化データにListDensityPlotを使う:
ListDensityPlot[Table[x + Sin[3x + y ^ 2], {x, -3, 3, 0.1}, {y, -3, 3, 0.1}], ColorFunction -> "SunsetColors"]ArrayPlot3Dをデータの3D配列に使う:
ArrayPlot3D[RandomInteger[5, {3, 4, 5}]]GraphPlotを隣接行列の可視化に使う:
GraphPlot[RandomChoice[{0.01, 0.99} -> {1, 0}, {100, 100}]]考えられる問題 (2)
MaxPlotPointsを使うともとのデータには存在しないアーチファクトが生まれるかもしれない:
sp = SparseArray[{{i_, j_} /; Mod[i - j, 3] == 0 -> 1}, {40, 40}];MatrixPlot[sp]MaxPlotPointsオプションの値が小さいと,すべての項目が非零になる:
MatrixPlot[sp, MaxPlotPoints -> 20]MatrixPlot[{{10, 2, 3}, {4, 1, 5}, {6, -10, 1.*^-100}}]おもしろい例題 (1)
Sin関数を整数点でプロットする:
MatrixPlot[Table[Sin[x y / 100], {x, -50, 50}, {y, -50, 50}]]関連するガイド
-
▪
- データの可視化 ▪
- GPU計算 ▪
- 行列と線形代数 ▪
- NVIDIAを使ったGPU計算 ▪
- Appleを使ったGPU計算 ▪
- グラフと行列
テキスト
Wolfram Research (2007), MatrixPlot, Wolfram言語関数, https://reference.wolfram.com/language/ref/MatrixPlot.html (2014年に更新).
CMS
Wolfram Language. 2007. "MatrixPlot." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/MatrixPlot.html.
APA
Wolfram Language. (2007). MatrixPlot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MatrixPlot.html
BibTeX
@misc{reference.wolfram_2026_matrixplot, author="Wolfram Research", title="{MatrixPlot}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/MatrixPlot.html}", note=[Accessed: 06-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_matrixplot, organization={Wolfram Research}, title={MatrixPlot}, year={2014}, url={https://reference.wolfram.com/language/ref/MatrixPlot.html}, note=[Accessed: 06-November-2026]}