【问题标题】:How to use Plotly with Zeppelin如何在 Zeppelin 中使用 Plotly
【发布时间】:2016-09-10 04:27:40
【问题描述】:

我见过zeppelin-plotly,但它似乎太复杂了。让我担心的另一件事是它涉及修改 zeppelin 的 .war 文件,我不想因错误而破坏事情。

还有其他方法可以将 Plotly 与 Zeppelin 一起使用吗?

【问题讨论】:

    标签: python apache-spark plotly apache-zeppelin


    【解决方案1】:

    使用%angular 解释器功能解决了这个问题。以下是让它工作的完整步骤

    1: 安装情节(如果你还没有)

    %sh pip install plotly
    

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

    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))
    

    此自定义绘图功能使用角度解释器来绘制 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"
        )
    })
    

    【讨论】:

      猜你喜欢
      • 2017-11-04
      • 2017-07-13
      • 2017-07-14
      • 2018-05-15
      • 2016-02-14
      • 2017-03-25
      • 2017-06-14
      • 2018-05-30
      • 2020-06-03
      相关资源
      最近更新 更多