首页 > 解决方案 > 用seaborn制作的解包情节

问题描述

我正在尝试保存此图,但是当我运行以下代码时,我得到TypeError: cannot unpack non-iterable AxesSubplot object. 我该如何解决?

filename = 'Results/confusion_matrix_'+model_name+'.png'
cm = confusion_matrix(labels_test_true, labels_test_pred[0,:])
fig, ax= plt.subplot()
sns.heatmap(cm, annot=True, fmt='g', ax=ax);
# labels, title and ticks
ax.set_xlabel('Predicted labels');ax.set_ylabel('True labels'); 
ax.set_title('Confusion Matrix'); 
ax.xaxis.set_ticklabels(['normal', 'anomaly']); ax.yaxis.set_ticklabels(['anomaly', 'normal']);
fig.savefig(filename)

标签: pythonplotseaborn

解决方案


推荐阅读