【问题标题】:Matplotlib:empty confusion matrixMatplotlib:空混淆矩阵
【发布时间】:2012-09-20 20:21:16
【问题描述】:

需要用这个脚本绘制一个混淆矩阵。通过运行它会出现一个空图。似乎我接近解决方案。有什么提示吗?

from numpy import *
import matplotlib.pyplot as plt
from pylab import *

conf_arr = [[50.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [3.0, 26.0, 0.0, 0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0], [4.0, 1.0, 0.0, 5.0, 0.0, 0.0, 0.0], [3.0, 0.0, 1.0, 0.0, 6.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 47.0, 0.0], [2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 8.0]]

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()
ax = fig.add_subplot(111)
res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest')
cb = fig.colorbar(res)
savefig("confmat.png", format="png")

谢谢,我知道了。现在,x 轴上的刻度非常小(图形尺寸为:3 cm x 10 cm 左右)。我怎样才能放大它们以获得更比例的图形,比如说 10cm x 10cm 的图?一个可能的原因是我将图表可视化为子图?无法找到合适的文献来调整它。

【问题讨论】:

    标签: matplotlib confusion-matrix


    【解决方案1】:

    在添加新人物之前,您无需清除当前人物 (plt.clf())。

    #plt.clf()  # <<<<< here
    fig = plt.figure()
    ax = fig.add_subplot(111)
    

    【讨论】:

    • 谢谢,我有情节。现在,x 轴上的刻度非常小(图形尺寸为:3 cm x 10 cm 左右)。我怎样才能放大它们以获得更比例的图形,比如说 10cm x 10cm 的图?可能的原因是我将图表可视化为子图吗?
    • 你为什么不把它作为一个单独的问题(或谷歌/查找文档)。
    • 刚刚找到了可能的解决方案,无需追问...谢谢
    猜你喜欢
    • 2015-12-17
    • 2020-10-01
    • 2012-01-20
    • 2019-11-23
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 2014-07-09
    • 1970-01-01
    相关资源
    最近更新 更多