I have figure instances, and I want to plot them side by side (e.g. two figures in one row and two columns). Below is the sample code which returns the figure instance.
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
import matplotlib.pyplot as plt
def build_confusion_matrix_test():
cm = np.array([[379, 49],
[ 18 , 261]])
print(cm)
disp = ConfusionMatrixDisplay(confusion_matrix=cm,
display_labels=[0,1])
title_font = {'size':'13.5'} # Adjust to fit
disp.plot()
disp.ax_.set_title("title", fontdict = title_font)
return disp.figure_
# Function call
test_plot = build_confusion_matrix_test()
test_plot
I have many figure instances from different functions and I was expecting something like the below where I try to plot the same figure twice in one row but not sure how to make it work:
fig = plt.figure()
ax1 = fig.add_subplot(1,1)
test_plot
ax2 = fig.add_subplot(1,2)
test_plot