I'm generating 6 different confusion matrices for 6 different values of training data and I'm trying to save the generated confusion matrices as images. Unfortunately, when they save they keep saving as blank jpeg images; however, when I use show() to display them they are visible. Here is my code
for matrix in confusion_matrices:
fig = plt.figure()
plt.matshow(cm)
plt.title('Problem 1: Confusion Matrix Digit Recognition')
plt.colorbar()
plt.ylabel('True Label')
plt.xlabel('Predicated Label')
fig.savefig('confusion_matrix'+str(learning_values.pop())+'.jpg')
I'm using the following libraries:
import matplotlib.pyplot as plt
import numpy
from numpy import ravel, reshape, swapaxes
import scipy.io
from sklearn import svm
from sklearn.metrics import confusion_matrix
from random import sample
How do I efficiently save confusion matrices?
I fixed the problem I was having. In case anyone is wondering, I modified the code to this and it resolved the problem.
for matrix in confusion_matrices:
fig = plt.figure()
plt.matshow(cm)
plt.title('Problem 1: Confusion Matrix Digit Recognition')
plt.colorbar()
plt.ylabel('True Label')
plt.xlabel('Predicated Label')
plt.savefig('confusion_matrix'+str(learning_values.pop())+'.jpg')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With