Plotly saving multiple plots into a single html

前端 未结 3 1540
臣服心动
臣服心动 2021-02-01 09:57

I recently discovered plotly and find it really good for graphing, now I have a problem which I want to save multiple plot into a single html, how to do it please?

*I wa

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 10:44

    It depend how do you build the html page. If it is with from plotly.offline.plot(fig, filename='name.html') than it is not possible. As you mentioned than subplot are too small, you can play with play with height and weight variable in layout:

    On layout:

    from plotly.offline import plot
    from plotly.subplots import make_subplots
    import plotly.graph_objects as go
    
    fig = make_subplots(
    rows=3, cols=1, shared_xaxes=True, 
    vertical_spacing=0.02)
    
    fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]),
              row=3, col=1)
    
    fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]),
              row=2, col=1)
    
    fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]),
              row=1, col=1)
    
    fig.update_layout(height=1200, width=600,
                  title_text="Stacked Subplots with Shared X-Axes")
    fig['layout']['yaxis1'].update(domain=[0, 0.2])
    fig['layout']['yaxis2'].update(domain=[0.3, 0.7])
    fig['layout']['yaxis3'].update(domain=[0.8, 1])
    
    plotly.offline.plot(fig, filename='name.html')
    

    If you build by yourself the html page you can render the html divs as http://www.codingwithricky.com/2019/08/28/easy-django-plotly/ and play on height and width variable of layout to make it bigger or smaller.

提交回复
热议问题