Search code examples
pythonvisualizationgoogle-colaboratoryconfusion-matrix

Confusion matrix in Google colab is cutted off


I tried to visualize my Confusion matrix by the following code:

from mlxtend.plotting import plot_confusion_matrix
import matplotlib.pyplot as plt
import numpy as np
import sklearn as skplt
import scikitplot as skplt
skplt.metrics.plot_confusion_matrix(y_val, autokeras_predictions, figsize = (5, 5), title= 'My confusionmatrix' )
plt.figure(figsize = (10,7))

But it cuts off my confusion matrix above and below. (See picture) enter image description here

Can anyone help me? Thanks!


Solution

  • I had the same problem.

    I'm using Anaconda on Windows.

    For me, the following resolved the problem:

    from mlxtend.plotting import plot_confusion_matrix
    ...
    multiclass = confusion_matrix(test_y, predictions)
    class_names = ['16QAM', '32QAM', '64QAM', 'BPSK', 'QPSK', '8PSK']
    
    fig, ax = plot_confusion_matrix(conf_mat=multiclass, colorbar=True,
    show_absolute=False, show_normed=True, class_names=class_names)
    -->ax.margins(2,2) #just change the values til adjust to your screen.
    plt.show()
    

    My figure after adding the commented line