我正在开发一个Django项目,希望从CSV文件中获取数据并将其绘制到使用Django视图/模板构建的页面上。以下是我目前拥有的代码:
import matplotlib.pyplot as plt, mpld3
graph = plt.plot([1,2,3,4])
g = mpld3.fig_to_html(graph)
return HttpResponse(g)
然而,当我运行此代码时,出现错误:
AttributeError: 'list' object has no attribute 'savefig'
有人知道我哪里出错了吗?或者我如何创建图形,可以将其添加到我已经拥有的页面中,而不是MPLD3为您呈现的页面。