【问题标题】:Plot value in unequal list/array shape using Imshow and cmap [duplicate]使用 Imshow 和 cmap 绘制不等列表/数组形状的值 [重复]
【发布时间】:2017-01-10 13:43:59
【问题描述】:

我想将我的价值观绘制成这样:

我的列表中有 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]]

我尝试遵循混淆矩阵方法,但它似乎仅限于相等的数组形状Confusion Matrix with number of classified/misclassified instances on it (Python/Matplotlib)

有什么建议吗?

【问题讨论】:

  • 已答复!我忘了从 numpy 导入 * 从 pylab 导入 *

标签: python-2.7 numpy matplotlib confusion-matrix


【解决方案1】:

只需复制您提出的问题的代码:Confusion Matrix with number of classified/misclassified instances on it (Python/Matplotlib):

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)

【讨论】:

  • 嗨@ibellomo 谢谢!愚蠢的我,我只是错过了导入 * 模块
猜你喜欢
  • 2021-09-22
  • 1970-01-01
  • 2016-09-27
  • 1970-01-01
  • 2023-02-21
  • 2014-10-03
  • 1970-01-01
  • 2023-04-02
  • 2020-04-26
相关资源
最近更新 更多