【发布时间】:2017-11-09 11:01:38
【问题描述】:
我今天一直在阅读有关如何在 Django 模板中渲染 matplotlib.pyplot。
我找到了散景库,并试图将我的 matplotib 在有效输入中转换为散景组件。我读到 .to_boke 方法已弃用。
datos = np.random.randn(1000)
## Discretizamos el conjunto de valores en n intervalos,
## en este caso 8 intervalos
datosbin = np.histogram(datos,
bins=np.linspace(np.min(datos), np.max(datos), 9))[0]
## Los datos los queremos en tanto por ciento
datosbin = datosbin * 100. / len(datos)
## Los datos los queremos en n direcciones/secciones/sectores,
## en este caso usamos 8 sectores de una circunferencia
sect = np.array([90, 45, 0, 315, 270, 225, 180, 135]) * 2. * math.pi / 360.
nombresect = ['E', 'NE', 'N', 'NW', 'W', 'SW', 'S', 'SE']
## Dibujamos la rosa de frecuencias
plt.axes([0.1, 0.1, 0.8, 0.8], polar=True)
plt.bar(sect, datosbin, align='center', width=45 * 2 * math.pi / 360.,
facecolor='b', edgecolor='k', linewidth=2, alpha=0.5)
plt.thetagrids(np.arange(0, 360, 45), nombresect, frac=1.1, fontsize=10)
plt.title(u'Procedencia de las nubes en marzo')
script, div = components(plt, CDN)
return render(request, 'consulta/resultado/imprimir.html', {'variables': variables,
'respuesta3': peticion3.content,
'lugar': lugar,
'hora_actual': hora_actual,
'hora_siguiente': hora_siguiente,
'dias': horas,
'Variables': variables_posibles,
'latitud':latitud,
'longitud': longitud,
"the_script": script,
"the_div": div})
我有一个 valueError(显然 matplotlib.pyplot 不是有效输入):
我在这里堆。这是我第一次接触图书馆和 matplot。
感谢您的帮助。非常感谢。
PS:我已经编码并尝试打印的图:
【问题讨论】:
-
自 Bokeh 12.5(2017 年 4 月)以来,support for Matplotlib has been deprecated,因此
mpl.to_bokeh()不再可用。另请参阅 bryevdv 的 this Github comment。 -
我投票决定将此问题作为题外话结束,因为 Bokeh 不再提供 MPL 支持(并且很久没有提供)。如果 SO 不允许一个正确的答案来说明这一点(这只是唯一的答案),那么应该删除问题本身,以避免成为 Bokeh 用户混淆的来源。
标签: django python-3.x django-templates bokeh