Matplotlib:空的混淆矩阵
需要使用此脚本绘制混淆矩阵。通过运行它,将显示一个空绘图。看来我接近解决方案了。有什么提示吗Matplotlib:空的混淆矩阵,matplotlib,confusion-matrix,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
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的绘图?一个可能的原因是我将图形可视化为子图?无法找到合适的参考资料进行调整。在添加新图形之前,无需清除当前图形(
plt.clf()
)
#plt.clf() # <<<<< here
fig = plt.figure()
ax = fig.add_subplot(111)
#plt.clf()#谢谢,我有情节。现在,x轴上的刻度非常小(图形尺寸为:3 cm x 10 cm左右)。我怎样才能放大它们以获得更均衡的图形,比如说10cm x 10cm的绘图?一个可能的原因是我将图形可视化为一个子图?为什么不将其作为一个单独的问题(或谷歌/查找文档)。只找到一个可能的解决方案,无需提问…谢谢