【发布时间】:2019-08-08 13:19:28
【问题描述】:
plt.figure(figsize=(8, 8))
sns.heatmap(conf_matrix, annot=True, fmt="d");
plt.title("Confusion matrix")
plt.ylabel('True class')
plt.xlabel('Predicted class')
html_fig = mpld3.fig_to_html(plt,template_type='general')
plt.close(plt)
HTML 文件中用于获取图像的代码:
<div id="fig_container">
{{ div_figure|safe }}
</div>
使用最新版本的Python 和Django。执行时显示属性错误
模块'matplotlib.pyplot'没有属性'canvas'
我是新手,无法解决错误。请帮忙!!!
【问题讨论】:
-
请在代码 sn-p 周围添加几行上下文,特别是您对 pyplot 的导入和对 canvas 的使用。
-
您似乎调用了
mpld3.fig_to_html(matplotlib.pyplot),这是不正确的。该函数可能需要一个数字作为输入,fig = plt.figure(); ....; mpld3.fig_to_html(fig)
标签: django python-3.x matplotlib django-templates attributeerror