【发布时间】:2018-08-23 12:19:47
【问题描述】:
我正在尝试使用matplotlib 和mpld3 在我的Django 报告应用程序上生成一些html 图。
基本上,我有一个控制器用于以下情节:
from django.shortcuts import render
import mpld3
from matplotlib.pyplot import figure, title, bar
def cpfLogin(request):
mpl_figure = figure(1)
xvalues = (1,2,3,4,5)
yvalues = (1,2,3,4,5)
width = 0.5 # the width of the bars
title(u'Custom Bar Chart')
bar(xvalues, yvalues, width)
fig_html = mpld3.fig_to_html(mpl_figure)
context = {
'figure': fig_html,
}
return render(request, 'reports/CPFReport.html', context)
reports/CPFReport.html 的代码是:
{% load i18n %}
{% block extrahead %}
<style type="text/css">
.chart_title {
font-weight: bold;
font-size: 14px;
}
</style>
{% endblock %}
{% block content %}
<div id="content-main">
<div class="chart_title">
{% trans "Custom Bar Chart" %}
</div>
{{ figure|safe }}
</div>
{% endblock %}
代码执行正确,绘图正确显示,但几秒钟后应用程序终止并出现以下错误:
断言失败:(NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentBuildingLayerTree), 函数 NSViewSetCurrentlyBuildingLayerTreeForDisplay,文件 /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.20.106/AppKit.subproj/NSView.m, 第 14480 行。
我发现,如果我注释所有代码,则在调用任何 matplotlib 库时都会引发此异常。
有没有人有这个问题的解决方法或解决方案?
【问题讨论】:
-
我在 python 3.6 上遇到了同样的问题。
-
您找到解决方案了吗?也有这个问题
标签: python django macos python-2.7 matplotlib