Home > Software engineering >  How to include or deleat completely the figure axis using Sklearn ConfusionMatrixDisplay?
How to include or deleat completely the figure axis using Sklearn ConfusionMatrixDisplay?

Time:07-22

I am using the below code to generate a confusion matrix using the Sklearn library. But while saving the image the y-axis label i.e. True label is not printed completely. It is shown as . In the python console, it is printed okay, But I need a high-resolution image and hence I need to save the image. Also, the publisher wants only tiff or pdf format.

disp=ConfusionMatrixDisplay(confusion_matrix=cm1,display_labels=['anger','bordome','disgust','fear', 'happiness','sadness' ,'neutral'])
font={'size':'30'}
plt.rc('font',**font)
plt.rcParams['figure.figsize']=[20,20]
disp.plot(cmap='Blues',values_format='0.2f')
plt.xticks(rotation=45)
plt.savefig("Fig.5.tif",dpi=30)
plt.show()

Also can I remove both the axis labels somehow? As that would also solve my problem. Thanks

CodePudding user response:

The picture is a matplotlib plot. So, to remove the ticks for each axis and the labels, you can use set_ticks([]) which will remove both. I am using the sample from enter image description here

Update to keep tick labels, but remove axes labels

Replace the two set_ticks()rows with below.

plt.gca().xaxis.label.set_visible(False)
plt.gca().yaxis.label.set_visible(False)

enter image description here

  • Related