在 python 中将矩阵绘制为具有给定单元格大小的热图

Plot matrix as heatmap with given cell size in python

我尝试 google,但找不到任何答案。 我有一个带有值的 numpy ndarray,我想将其绘制为一个普通的(没有轴和东西)热图,其中每个矩形都按给定值着色。

我想让一个单元格的高度为1px,宽度为5px。

最终结果是png。

在 python 中有没有一种方法可以使用这些像元大小参数绘制此图?

我用给定的总宽和高尝试了 PIL,但图像看起来不清晰。

一切顺利, L.

编辑:好的,这是使用 scipy.misc.imsave() 函数

的另一种方法
import numpy as np
import matplotlib.cm as cm
import scipy.misc

# generate random data
data = np.random.rand(20,20)
# map the data to a color
colormap = cm.ScalarMappable(cmap="autumn")
im  = colormap.to_rgba(data)
# scale the data to a width of 5 pixels
im = np.repeat(im, 5, axis=1)
# save the picture
scipy.misc.imsave('test.png', im)