将矩阵转换为图像

Tyl*_*ler 18 python image matrix

我将如何将一组int的列表转换为Python中的矩阵图?

示例数据集是:

[[3, 5, 3, 5, 2, 3, 2, 4, 3, 0, 5, 0, 3, 2],
 [5, 2, 2, 0, 0, 3, 2, 1, 0, 5, 3, 5, 0, 0],
 [2, 5, 3, 1, 1, 3, 3, 0, 0, 5, 4, 4, 3, 3],
 [4, 1, 4, 2, 1, 4, 5, 1, 2, 2, 0, 1, 2, 3],
 [5, 1, 1, 1, 5, 2, 5, 0, 4, 0, 2, 4, 4, 5],
 [5, 1, 0, 4, 5, 5, 4, 1, 3, 3, 1, 1, 0, 1],
 [3, 2, 2, 4, 3, 1, 5, 5, 0, 4, 3, 2, 4, 1],
 [4, 0, 1, 3, 2, 1, 2, 1, 0, 1, 5, 4, 2, 0],
 [2, 0, 4, 0, 4, 5, 1, 2, 1, 0, 3, 4, 3, 1],
 [2, 3, 4, 5, 4, 5, 0, 3, 3, 0, 2, 4, 4, 5],
 [5, 2, 4, 3, 3, 0, 5, 4, 0, 3, 4, 3, 2, 1],
 [3, 0, 4, 4, 4, 1, 4, 1, 3, 5, 1, 2, 1, 1],
 [3, 4, 2, 5, 2, 5, 1, 3, 5, 1, 4, 3, 4, 1],
 [0, 1, 1, 2, 3, 1, 2, 0, 1, 2, 4, 4, 2, 1]]
Run Code Online (Sandbox Code Playgroud)

为了让您了解我正在寻找的东西,Mathematica中的MatrixPlot函数为我提供了此数据集的图像:

在此输入图像描述

谢谢!

Dr.*_*ius 15

你可以试试

from pylab import *
A = rand(5,5)
figure(1)
imshow(A, interpolation='nearest')
grid(True)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

资源


小智 9

也许来自matplotlib的matshow()就是你所需要的.

  • 还有pcolor:http://matplotlib.sourceforge.net/examples/pylab_examples/pcolor_demo.html (3认同)