Python 2.7 使用Imshow和cmap以不等列表/数组形状打印值

Python 2.7 使用Imshow和cmap以不等列表/数组形状打印值,python-2.7,numpy,matplotlib,confusion-matrix,Python 2.7,Numpy,Matplotlib,Confusion Matrix,我想将我的值绘制成如下所示: 列表中有4x12个值 values = [[2.78, 2.78, 2.78, 2.79, 2.79, 2.79, 2.8, 2.8, 2.81, 2.82, 2.82, 2.77], [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.0, 3.01, 3.02, 3.03, 2.98], [3.01, 3.01, 3.01, 3.01, 3.01, 3.02, 3.02, 3.03

我想将我的值绘制成如下所示:

列表中有4x12个值

values = [[2.78, 2.78, 2.78, 2.79, 2.79, 2.79, 2.8, 2.8, 2.81, 2.82, 2.82, 2.77], 
          [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.0, 3.01, 3.02, 3.03, 2.98], 
          [3.01, 3.01, 3.01, 3.01, 3.01, 3.02, 3.02, 3.03, 3.04, 3.04, 3.05, 3.01], 
          [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.01, 3.01, 3.02, 3.03, 2.99]]
我尝试过使用混淆矩阵法,但它似乎仅限于相等的数组形状


有什么建议吗?

只需复制你提出的问题的代码::


Hi@ibellomo谢谢!愚蠢的我,我只是错过了导入*模块!我忘了从numpy导入*从pylab导入*
from numpy import *
import matplotlib.pyplot as plt
from pylab import *

conf_arr = [[2.78, 2.78, 2.78, 2.79, 2.79, 2.79, 2.8, 2.8, 2.81, 2.82, 2.82, 2.77], 
          [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.0, 3.01, 3.02, 3.03, 2.98], 
          [3.01, 3.01, 3.01, 3.01, 3.01, 3.02, 3.02, 3.03, 3.04, 3.04, 3.05, 3.01], 
          [2.98, 2.98, 2.98, 2.99, 2.99, 2.99, 3.0, 3.01, 3.01, 3.02, 3.03, 2.99]]

norm_conf = []
for i in conf_arr:
        a = 0
        tmp_arr = []
        a = sum(i,0)
        for j in i:
                tmp_arr.append(float(j)/float(a))
        norm_conf.append(tmp_arr)

plt.clf()
fig = plt.figure(figsize=(14, 5))
ax = fig.add_subplot(111)
#res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest')
#cb = fig.colorbar(res)

res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest')
for i, cas in enumerate(conf_arr):
    for j, c in enumerate(cas):
        if c>0:
            plt.text(j-.2, i+.2, c, fontsize=14)
cb = fig.colorbar(res)