I would like to produce two confusion matrix and only show one colorbar. I am basically trying to merge this scikit-learn code with this answer.
My code looks like this:
import numpy as np
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=1, ncols=2)
classes = ["A", "B"]
for i, ax in enumerate(axes.flat):
cm = np.random.random((2,2))
im = ax.imshow(cm, vmin=0, vmax=1)
plt.title("Title {}".format(i))
tick_marks = np.arange(2)
plt.xticks(tick_marks, classes, rotation=45)
plt.yticks(tick_marks, classes)
for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
plt.text(j, i, format(cm[i, j], '.5f'),
horizontalalignment="center",
color="white")
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.tight_layout()
fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.88, 0.15, 0.05, 0.6])
fig.colorbar(im, cax=cbar_ax)
plt.show()
So everything is being plotted on the last image. Two questions:
- how can I separate the two?
- how can i start the colorbar where the matrix start, even if it has no label?