python - 用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)
解决方案
推荐阅读
- jhipster - 在生产中有数据库时编辑实体
- scala - 如何使 ScalaTest 中的测试失败并打印堆栈跟踪?
- genexus - 期望“EndNew”命令关闭“New”。属相
- c++ - 在类中声明的 lambda 表达式是否是该类的成员?
- html - 如何响应式地使带有破折号的单词转到下一行而不是中断?
- c++ - 在类中将静态数组更改为动态数组
- python - python pandas检测单元格中的颜色并添加为新列
- javascript - 如何选择特定正则表达式的反面?
- regex - 在 Notepad++ 中通过正则表达式匹配单行注释
- xpath - 如何在此网站上指定正确的 xpath 进行解析?