我不能让像这样的imshow图上的colorbar与图形的高度相同,而不是事后使用Photoshop.我如何达到匹配的高度?
以下代码绘制了一个混淆矩阵:
from sklearn.metrics import ConfusionMatrixDisplay
confusion_matrix = confusion_matrix(y_true, y_pred)
target_names = ["aaaaa", "bbbbbb", "ccccccc", "dddddddd", "eeeeeeeeee", "ffffffff", "ggggggggg"]
disp = ConfusionMatrixDisplay(confusion_matrix=confusion_matrix, display_labels=target_names)
disp.plot(cmap=plt.cm.Blues, xticks_rotation=45)
plt.savefig("conf.png")
Run Code Online (Sandbox Code Playgroud)
这个情节有两个问题。
为了解决第一个问题,我尝试使用poof(bbox_inches='tight')它,不幸的是 sklearn 不可用。在第二种情况下,我尝试了以下2.解决方案,这导致了完全扭曲的情节。
总而言之,我正在为这两个问题而苦苦挣扎。