如何将 matplotlib.pyplot 转换为散景图
How to convert a matplotlib.pyplot to a bokeh plot
我今天一直在阅读如何在 Django 模板中呈现 matplotlib.pyplot。
我找到了 bokeh 库,我试图将有效输入中的 matplotib 转换为 bokeh 组件。我阅读 .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 或 Matplotlib 中,没有任何特性或函数可以将 Matplotlib 输出转换为 Bokeh 输出。因此,本题答案为:
What you are asking for is not possible.
(作为 Bokeh 的共同创建者和主要维护者发言)重要的是用户要清楚明确地理解没有 "magic bullet" 可以将 MPL 转换为 Bokeh。其他都是错误信息).
生成 Bokeh 输出的唯一选择是直接使用本机 Bokeh API,例如bokeh.plotting
API. In particular, you might want to look at the wedge glyph,但请注意,从 1.2.0
开始,Bokeh 没有任何内置径向轴,因此您必须绘制所有轴元素和标签 "by hand".
我今天一直在阅读如何在 Django 模板中呈现 matplotlib.pyplot。
我找到了 bokeh 库,我试图将有效输入中的 matplotib 转换为 bokeh 组件。我阅读 .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 或 Matplotlib 中,没有任何特性或函数可以将 Matplotlib 输出转换为 Bokeh 输出。因此,本题答案为:
What you are asking for is not possible.
(作为 Bokeh 的共同创建者和主要维护者发言)重要的是用户要清楚明确地理解没有 "magic bullet" 可以将 MPL 转换为 Bokeh。其他都是错误信息).
生成 Bokeh 输出的唯一选择是直接使用本机 Bokeh API,例如bokeh.plotting
API. In particular, you might want to look at the wedge glyph,但请注意,从 1.2.0
开始,Bokeh 没有任何内置径向轴,因此您必须绘制所有轴元素和标签 "by hand".