更改y标签在混淆矩阵matplotlib中的位置

时间:2020-01-10 14:23:08

标签: python matplotlib scikit-learn confusion-matrix

我使用以下代码绘制了一个混淆矩阵:

cm = confusion
fig, ax1 = plt.subplots()
fig.set_figheight(6)
fig.set_figwidth(10)
plt.clf()
plt.imshow(cm, interpolation='nearest', cmap=plt.cm.Blues)
classNames = ['no irrigation','irrigation']
plt.ylabel('True label', size = 20)
plt.xlabel('Predicted label', size = 20)
tick_marks = np.arange(len(classNames))
plt.xticks(tick_marks, classNames, rotation=45, size = 15)
plt.yticks(tick_marks, classNames, size = 15)
plt.yticks
s = [['TN','FP'], ['FN', 'TP']]        
plt.text(0-0.15,0+0.3, f'TN = {TN}', size = 20)        
plt.text(0-0.15,1-0.25, f'FP = {FP}', size = 20)  
plt.text(1-0.15,0+0.3, f'FN = {FN}', size = 20)  
plt.text(1-0.15,1-0.25, f'TP = {TP}', size = 20)  

plt.show()

输出是这样的:

enter image description here

如您所见,x标签在x轴的中间很好地对齐,但是y标签被绘制在y轴的边缘。我看到了许多类似的问题,例如hereherehere,但是那里的解决方案没有用。 如何设置y标签的位置?

0 个答案:

没有答案