如何与Zeppelin一起使用Plotly [英] How to use Plotly with Zeppelin

查看:93
本文介绍了如何与Zeppelin一起使用Plotly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过 zeppelin-plotly ,但这似乎太复杂了.让我担心的其他事情是,它涉及修改齐柏林飞艇的 .war 文件,而我不想因为出错而破坏.

I've seen zeppelin-plotly but it seems too complicated. The other things that worries me is that it involves modifying zeppelin's .war file and I don't want to break things by error.

还有另一种将Zeppelin与Zeppelin结合使用的方法吗?

Is there another way to use Plotly with Zeppelin?

推荐答案

使用%angular 解释器功能将其弄清楚.这是使其正常运行的完整步骤

Figured it out using the %angular interpreter feature. Here are the full steps to get it working

%sh pip install plotly

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

You can also do this on the terminal if you have access to it

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 一样使用它.

This custom plot funtion uses the angular interpreter to plot html. It take the same parameters as plotly.offline.plot plus some extra parameters for the div's dimensions (I had bad results without these). Use it as you normally would use plotly.offline.plot.

这些情节是互动的!您不需要 iplot ,这里定义的 plot 函数也适用于3D交互式绘图.

These plots are interactive! You don't need iplot, the plot function defined here works for 3D interactive plots as well.

%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"
    )
})

这篇关于如何与Zeppelin一起使用Plotly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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