如何将matplotlib.pyplot转换为散景图

Hug*_*L.M 3 django django-templates python-3.x bokeh

今天,我一直在阅读有关如何在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})
Run Code Online (Sandbox Code Playgroud)

我有一个valueError(显然matplotlib.pyplot不是有效的输入):

在此处输入图片说明

我在这里 这是我第一次使用图书馆和Matplot。

感谢您的帮助。非常感谢。

PS:我已编码并尝试打印的图形:

在此处输入图片说明

big*_*dot 6

您所要求的内容不受支持,并且不存在。Bokeh或Matplotlib中没有将Matplotlib输出转换为Bokeh输出的功能部件。因此,此问题的答案是:

您所要求的是不可能的。

(作为Bokeh的共同创建者和首席维护者)重要的是,用户必须清楚明确地理解,没有将MPL转换为Bokeh的“灵丹妙药”。其他都是错误的信息

生成Bokeh输出的唯一选择是直接使用本地Bokeh API,例如bokeh.plottingAPI。特别是,您可能想看一下楔形字形,但是建议到1.2.0为止,Bokeh没有任何内置的径向轴,因此您必须“手工”绘制所有轴元素和标签。