MatrixPlot[m]
绘制一个可视化描述矩阵中元素值的图形.
MatrixPlot
MatrixPlot[m]
绘制一个可视化描述矩阵中元素值的图形.
更多信息和选项
- 默认情况下,MatrixPlot[m] 向下纵向连续排列 m 行,将列横向连续排列,如同格式化普通的矩阵一样.
- 默认情况下,MatrixPlot 中 0 值显示为白色,而负值则是使用蓝色表示,正值用红色表示.
- 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}}]接近 0 的元素用灰色阴影表示; 非常接近于0的元素用白色显示:
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 和 ColorFunction 为元素上色, ColorRules 具有高优先级:
MatrixPlot[Table[Mod[i ^ 2 + j ^ 2, 5], {i, 20}, {j, 20}], ColorRules -> {0 -> Red, 1 -> Green, 2 -> Blue}]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 连用,并有更高的优先级:
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 中首先输入的两个元素,指出了包含的行和列的范围:
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 绘制三维数据数组:
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 语言. 2007. "MatrixPlot." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2014. https://reference.wolfram.com/language/ref/MatrixPlot.html.
APA
Wolfram 语言. (2007). MatrixPlot. Wolfram 语言与系统参考资料中心. 追溯自 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: 12-September-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: 12-September-2026]}