如何使用Zeppelin Plotly

Cri*_*cia 6 python plotly apache-spark apache-zeppelin

我已经看过zeppelin-plotly,但它似乎太复杂了.令我担心的其他事情是它涉及修改zeppelin的.war文件,我不想错误地解决问题.

还有另一种方法可以使用Plotly和Zeppelin吗?

Cri*_*cia 9

使用%angular解释器功能将其计算出来.以下是使其正常运行的完整步骤

1:绘图安装(如果没有)

%sh pip install plotly
Run Code Online (Sandbox Code Playgroud)

如果您有权访问终端,也可以在终端上执行此操作

2:定义绘图功能

def plot(plot_dic, height=500, width=500, **kwargs):
    kwargs['output_type'] = 'div'
    plot_str = plotly.offline.plot(plot_dic, **kwargs)
    print('%%angular <div style="height: %ipx; width: %spx"> %s </div>' % (height, width, plot_str))
Run Code Online (Sandbox Code Playgroud)

这个自定义绘图功能使用角度解释器来绘制html.它采用相同的参数,plotly.offline.plot加上div的维度的一些额外参数(没有这些参数,我的结果很糟糕).像平常一样使用它plotly.offline.plot.

注意

这些情节是互动的!您不需要iplot,plot此处定义的功能也适用于3D交互式图.

完整的例子

%pyspark

import plotly
from plotly.graph_objs import Scatter, Layout


def plot(plot_dic, height=500, width=500, **kwargs):
    kwargs['output_type'] = 'div'
    plot_str = plotly.offline.plot(plot_dic, **kwargs)
    print('%%angular <div style="height: %ipx; width: %spx"> %s </div>' % (height, width, plot_str))


plot({
    "data": [
        Scatter(x=[1, 2, 3, 4], y=[4, 5, 3, 7])
    ],
    "layout": Layout(
        title="hello world"
    )
})
Run Code Online (Sandbox Code Playgroud)