如何将matplotlib.pyplot转换为散景图 [英] How to convert a matplotlib.pyplot to a bokeh plot

查看:101
本文介绍了如何将matplotlib.pyplot转换为散景图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天一直在阅读有关如何在Django模板中渲染matplotlib.pyplot的信息.

I have been reading today about how to render a matplotlib.pyplot in a Django template.

我找到了bokeh库,并且试图将有效输入中的matplotib转换为bokeh组件.我读到 .to_boke 方法已已弃用.

I found bokeh library and I was trying to convert my matplotib in a valid input to bokeh components. I read .to_boke method is deprecated.

        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不是有效的输入):

I have a valueError (obviously matplotlib.pyplot is not a valid input):

我在这里堆放.这是我第一次使用图书馆和Matplot.

I'm stack here. It's my first time with the library and matplot.

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

I appreciate any help. Thank you so much.

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

PS: the figure I have coded and I'm trying to print:

推荐答案

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

What you are asking for is not supported and does not exist. There is no feature or function, in either Bokeh or Matplotlib, that will convert Matplotlib output to Bokeh output. Therefore, the answer to this question is:

您要的是不可能的.

What you are asking for is not possible.

(作为Bokeh的共同创建者和主要维护者)对于用户而言,清楚明确地了解没有将MPL转换为Bokeh的灵丹妙药"是很重要的. 其他信息).

生成Bokeh输出的唯一选择是直接使用本机Bokeh API,例如 bokeh.plotting API.特别是,您可能需要查看 wedge字形,但是建议从1.2.0开始,Bokeh没有内置的径向轴,因此您必须手动"绘制所有轴元素和标签.

The only option for generating Bokeh output is to use native Bokeh APIs directly, e.g. the bokeh.plotting API. In particular, you might want to look at the wedge glyph, however be advised that as of 1.2.0, Bokeh does not have any built-in radial axis, so you would have to draw all the axis elements and labels "by hand".

这篇关于如何将matplotlib.pyplot转换为散景图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆