Matplotlib:空混淆矩阵

时间:2012-09-20 09:08:10

标签: matplotlib confusion-matrix

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

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 10 cm的图形?可能的原因是我将图形可视化为子图?无法找到合适的文献进行调整。

1 个答案:

答案 0 :(得分:0)

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

#plt.clf()  # <<<<< here
fig = plt.figure()
ax = fig.add_subplot(111)
相关问题