在没有子图的情况下在1页上绘制多个阴谋图

时间:2017-10-19 01:24:36

标签: python plotly plotly-dash

我希望在1 html页面上有多个情节图而不使用tools.make_subplots方法。 (我不想使用它,因为我发现它不容易阅读,我想在每个子绘图面板中有一个独特的图例和布局。)

我想用自己独特的布局定义2个数字,并在页面上任意排列。我想我知道如何使用html.Div对象使用破折号,但我想知道是否有一种简单的方法只使用plotly来做这个?

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,并遵循此处发布的解决方案: Plotly: Plot multiple figures as subplots来自Esostack

但是,当我将多个图形的html转储到单个文本文件中时,发现添加的每个图形的文件大小增加了5MB。其中99.9%是由Java脚本素材引起的,该素材是通过添加以使绘图具有交互性而添加的。幸运的是,他们还实现了一个参数来指定是否要包含js。因此,您只需要在第一个图形中包含它,然后在其余图形中跳过它,就像在以下功能中所做的一样。希望能对您有所帮助:

def figures_to_html(figs, filename):
    '''Saves a list of plotly figures in an html file.

    Parameters
    ----------
    figs : list[plotly.graph_objects.Figure]
        List of plotly figures to be saved.

    filename : str
        File name to save in.

    '''
    import plotly.offline as pyo

    dashboard = open(filename, 'w')
    dashboard.write("<html><head></head><body>" + "\n")

    add_js = True
    for fig in figs:

        inner_html = pyo.plot(
            fig, include_plotlyjs=add_js, output_type='div'
        )

        dashboard.write(inner_html)
        add_js = False

    dashboard.write("</body></html>" + "\n")

答案 1 :(得分:0)

所以,总而言之,我还没有找到一种方法来完全用剧情来做这件事。下面是我使用Dash执行此操作的代码,该代码运行良好:

第1步:制作一些情节图

import plotly.offline as pyo
import plotly.graph_objs as go
import plotly as py
fig1 = go.Scatter(y=[1,2,3])
fig2 = go.Scatter(y=[3,2,1])
plots = [fig1, fig2]

第2步:制作破折号Div对象:

app = dash.Dash()
layout = html.Div(
        [html.Div(plots[i], style=col_style[i]) for i in range(len(plots))],
        style = {'margin-right': '0px'}
    )

第3步:运行破折号

app.layout = layout
app.run_server(port=8052)
相关问题