Got it 👍 — the bar on the right side is the colorbar that ConfusionMatrixDisplay adds by default.
You can remove it by setting colorbar=False when plotting.
Here’s the updated version of your Jupyter Notebook code with no colorbar:
pythonCopy codeimport pandas as pd
from sklearn.metrics import classification_report, confusion_matrix, ConfusionMatrixDisplay
import matplotlib.pyplot as plt
Test split -- 100 steps --
belief_path = "/home/esther/PycharmProjects/religious-paths/extracting-paths/predicting_practice_and_belief/instruct_fine_tuning/data/predictions/may2025/7B_belief_train_semi_balanced_mistral7B_300_seed_1_2025_100_363_samples_test_split.csv"
mistral_belief = pd.read_csv(belief_path, index_col=0, keep_default_na=True)
mistral_belief.pred_label = mistral_belief.pred_label.fillna("None")
mistral_belief.labels = mistral_belief.labels.fillna("None")
print("Test split: Mistral belief for 100 steps")
print(classification_report(mistral_belief.labels, mistral_belief.pred_label))
belief_classes = sorted(set(mistral_belief.labels.unique()) | set(mistral_belief.pred_label.unique()))
cm_test = confusion_matrix(
mistral_belief.labels,
mistral_belief.pred_label,
labels=belief_classes,
normalize="true"
) * 100 # percentages
disp_test = ConfusionMatrixDisplay(confusion_matrix=cm_test, display_labels=belief_classes)
fig, ax = plt.subplots(figsize=(8, 6))
disp_test.plot(cmap=plt.cm.Blues, xticks_rotation="vertical", values_format=".1f", ax=ax, colorbar=False)
plt.title("Confusion Matrix (%): Belief Test Data")
plt.savefig("belief_confusion_matrix.pdf", bbox_inches="tight")
plt.show()
Test split -- 100 steps --
practice_path = "/home/esther/PycharmProjects/religious-paths/extracting-paths/predicting_practice_and_belief/instruct_fine_tuning/data/predictions/may2025/7B_practice_train_semi_balanced_2025_7Binstruct_300_steps_seed_5_100_357_samples_test_split.csv"
mistral_practice = pd.read_csv(practice_path, index_col=0, keep_default_na=True)
mistral_practice.pred_label = mistral_practice.pred_label.fillna("None")
mistral_practice.labels = mistral_practice.labels.fillna("None")
print("Test split Mistral practice for 100 steps")
print(classification_report(mistral_practice.labels, mistral_practice.pred_label))
practice_classes = sorted(set(mistral_practice.labels.unique()) | set(mistral_practice.pred_label.unique()))
cm_test = confusion_matrix(
mistral_practice.labels,
mistral_practice.pred_label,
labels=practice_classes,
normalize="true"
) * 100 # percentages
disp_test = ConfusionMatrixDisplay(confusion_matrix=cm_test, display_labels=practice_classes)
fig, ax = plt.subplots(figsize=(8, 6))
disp_test.plot(cmap=plt.cm.Blues, xticks_rotation="vertical", values_format=".1f", ax=ax, colorbar=False)
plt.title("Confusion Matrix (%): Practice Test Data")
plt.savefig("practice_confusion_matrix.pdf", bbox_inches="tight")
plt.show()
✅ Now the confusion matrices will be clean, with no colorbar on the right.
Would you like me to also add the percentage symbol (%) inside the cells (instead of just 42.3 → 42.3%)?